Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 need help with ball streak
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Azzy




PostPosted: Tue Jan 13, 2004 4:20 pm   Post subject: need help with ball streak

got me a big probelm.this is for my project and for this step i need to make a ball move up and down.problem is that when it does move there's a streak left behind.
i always could use some help shortening it as well.

here it is

code:
setscreen ("graphics:700,400")

process Ball_1
    loop
        for u : 1 .. 290
            Draw.FillOval (200, 54 + u, 30, 30, magenta)
            delay (10)
        end for
        for d : 1 .. 290
            Draw.FillOval (200, 345 - d, 30, 30, magenta)
        end for
    end loop
end Ball_1



%Bottom Horizontal
Draw.FillBox (0, 0, 20, 20, green)
Draw.FillBox (25, 0, 45, 20, 12)
Draw.FillBox (50, 0, 70, 20, green)
Draw.FillBox (75, 0, 95, 20, 12)
Draw.FillBox (100, 0, 120, 20, green)
Draw.FillBox (125, 0, 145, 20, 12)
Draw.FillBox (150, 0, 170, 20, green)
Draw.FillBox (175, 0, 195, 20, 12)
Draw.FillBox (200, 0, 220, 20, green)
Draw.FillBox (225, 0, 245, 20, 12)
Draw.FillBox (250, 0, 270, 20, green)
Draw.FillBox (275, 0, 295, 20, 12)
Draw.FillBox (300, 0, 320, 20, green)
Draw.FillBox (325, 0, 345, 20, 12)
Draw.FillBox (350, 0, 370, 20, green)
Draw.FillBox (375, 0, 395, 20, 12)
Draw.FillBox (400, 0, 420, 20, green)
Draw.FillBox (425, 0, 445, 20, 12)
Draw.FillBox (450, 0, 470, 20, green)
Draw.FillBox (475, 0, 495, 20, 12)
Draw.FillBox (500, 0, 520, 20, green)
Draw.FillBox (525, 0, 545, 20, 12)
Draw.FillBox (550, 0, 570, 20, green)
Draw.FillBox (575, 0, 595, 20, 12)
Draw.FillBox (600, 0, 620, 20, green)
Draw.FillBox (625, 0, 645, 20, 12)
Draw.FillBox (650, 0, 670, 20, green)
Draw.FillBox (675, 0, 695, 20, 12)

%Top Horizontal
Draw.FillBox (0, 375, 20, 395, 12)
Draw.FillBox (25, 375, 45, 395, green)
Draw.FillBox (50, 375, 70, 395, 12)
Draw.FillBox (75, 375, 95, 395, green)
Draw.FillBox (100, 375, 120, 395, 12)
Draw.FillBox (125, 375, 145, 395, green)
Draw.FillBox (150, 375, 170, 395, 12)
Draw.FillBox (175, 375, 195, 395, green)
Draw.FillBox (200, 375, 220, 395, 12)
Draw.FillBox (225, 375, 245, 395, green)
Draw.FillBox (250, 375, 270, 395, 12)
Draw.FillBox (275, 375, 295, 395, green)
Draw.FillBox (300, 375, 320, 395, 12)
Draw.FillBox (325, 375, 345, 395, green)
Draw.FillBox (350, 375, 370, 395, 12)
Draw.FillBox (375, 375, 395, 395, green)
Draw.FillBox (400, 375, 420, 395, 12)
Draw.FillBox (425, 375, 445, 395, green)
Draw.FillBox (450, 375, 470, 395, 12)
Draw.FillBox (475, 375, 495, 395, green)
Draw.FillBox (500, 375, 520, 395, 12)
Draw.FillBox (525, 375, 545, 395, green)
Draw.FillBox (550, 375, 570, 395, 12)
Draw.FillBox (575, 375, 595, 395, green)
Draw.FillBox (600, 375, 620, 395, 12)
Draw.FillBox (625, 375, 645, 395, green)
Draw.FillBox (650, 375, 670, 395, 12)
Draw.FillBox (675, 375, 695, 395, green)

%Left Vertical
Draw.FillBox (0, 25, 20, 45, 12)
Draw.FillBox (0, 50, 20, 70, green)
Draw.FillBox (0, 75, 20, 95, 12)
Draw.FillBox (0, 100, 20, 120, green)
Draw.FillBox (0, 125, 20, 145, 12)
Draw.FillBox (0, 150, 20, 170, green)
Draw.FillBox (0, 175, 20, 195, 12)
Draw.FillBox (0, 200, 20, 220, green)
Draw.FillBox (0, 225, 20, 245, 12)
Draw.FillBox (0, 250, 20, 270, green)
Draw.FillBox (0, 275, 20, 295, 12)
Draw.FillBox (0, 300, 20, 320, green)
Draw.FillBox (0, 325, 20, 345, 12)
Draw.FillBox (0, 350, 20, 370, green)


%Right Vertical
Draw.FillBox (675, 25, 695, 45, green)
Draw.FillBox (675, 50, 695, 70, 12)
Draw.FillBox (675, 75, 695, 95, green)
Draw.FillBox (675, 100, 695, 120, 12)
Draw.FillBox (675, 125, 695, 145, green)
Draw.FillBox (675, 150, 695, 170, 12)
Draw.FillBox (675, 175, 695, 195, green)
Draw.FillBox (675, 200, 695, 220, 12)
Draw.FillBox (675, 225, 695, 245, green)
Draw.FillBox (675, 250, 695, 270, 12)
Draw.FillBox (675, 275, 695, 295, green)
Draw.FillBox (675, 300, 695, 320, 12)
Draw.FillBox (675, 325, 695, 345, green)
Draw.FillBox (675, 350, 695, 370, 12)

fork Ball_1
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Jan 13, 2004 4:24 pm   Post subject: (No subject)

you forgot to clear the ball... Confused you ether draw a white one on top of the ball or just use cls to clear the entire screen.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Azzy




PostPosted: Tue Jan 13, 2004 4:29 pm   Post subject: (No subject)

Sweet.Thanks.Now for step 3.Make a ball going from left to right.
Cervantes




PostPosted: Tue Jan 13, 2004 4:32 pm   Post subject: (No subject)

wow all those Draw.Box

use a for statement for that kind of thing, will save you SO much trouble.

you should also use offscreenonly

View.Set ("offscreenonly")

then use View.Update

if you want to learn about it go to your Turing folder (where its installed to, not where you save your programs necessarily) and go to examples\fun\SmoothAnimatedHouse.t

good example of how to use View.Update there.
Azzy




PostPosted: Wed Jan 14, 2004 4:09 pm   Post subject: (No subject)

thanks for that help guys.but now i got another problem.i need to make a counter that holds how many times two balls collide.i have absolutely no clue how to do that.can anyone help me?
shorthair




PostPosted: Wed Jan 14, 2004 4:29 pm   Post subject: (No subject)

if ball1x = ball2x and ball1y = ball2y then
count := count +1
end if
Azzy




PostPosted: Wed Jan 14, 2004 9:12 pm   Post subject: (No subject)

that does help a bit but i need it so even if it touches the ball at the rim it counts it.
Cervantes




PostPosted: Wed Jan 14, 2004 9:34 pm   Post subject: (No subject)

well are you going to make the balls bounce apart?? that would be super hard to do right (as I just found out recently Razz)

if not then what shorthair said will do it
Sponsor
Sponsor
Sponsor
sponsor
Azzy




PostPosted: Wed Jan 14, 2004 9:35 pm   Post subject: (No subject)

well...actually.that's part 5 and 6.5 is just it going backwards.easy.while 6 is using physics.bouncing everywhere.
Cervantes




PostPosted: Wed Jan 14, 2004 9:42 pm   Post subject: (No subject)

well if they aren't going to pass through each other then you could always use whatdotcolor to solve your worries Razz

or you could use an if statement to determine whether the x and y movement has changed, sorry though I gotta get to bed, can't think about it now.
Hunter007




PostPosted: Thu Jan 15, 2004 4:40 pm   Post subject: (No subject)

Hey I'm working on the same prog, but I'm behind Azzy. I need to know how to make the ball move. Thanks for any help.
shorthair




PostPosted: Thu Jan 15, 2004 5:02 pm   Post subject: (No subject)

okay about hte ballx and bally that i posted , depending on the diameter you can say
if ballx+10 = bally+10 then
count := count+1
end if
assuming that you have a radius of 10 on each side play with the numbers to see what works
Thuged_Out_G




PostPosted: Thu Jan 15, 2004 5:11 pm   Post subject: (No subject)

bouncing apart...would be something like this(i think)

if ballx=ballx2 and bally=bally2 then
ballxdir:=-ballxdir
ballydir:=-ballydir
end if
Azzy




PostPosted: Thu Jan 15, 2004 5:21 pm   Post subject: (No subject)

ok now some more problems.
1.when the counter goes up, it goes up twice
2.it doesn't go up if it's at the edge of the ball.

code:
setscreen ("graphics:700,400")
var collisions : int := 0
var ball1y : int := 54
var ball2x : int := 54

process Ball_1
    loop
        loop
            Draw.FillOval (200, ball1y + 1, 30, 30, magenta)
            delay (10)
            Draw.FillOval (200, ball1y + 1, 30, 30, white)
            ball1y:=ball1y+1
            exit when ball1y=344
        end loop
        loop
            Draw.FillOval (200, ball1y - 1, 30, 30, magenta)
            delay (10)
            Draw.FillOval (200, ball1y - 1, 30, 30, white)
            ball1y:=ball1y-1
            exit when ball1y=54
        end loop
    end loop
end Ball_1

process Ball_2
    loop
        loop
            Draw.FillOval (ball2x + 1, 245, 30, 30, yellow)
            delay (10)
            Draw.FillOval (ball2x + 1, 245, 30, 30, white)
            ball2x:=ball2x+1
            exit when ball2x=646
        end loop
        loop
            Draw.FillOval (ball2x - 1, 245, 30, 30, yellow)
            delay (10)
            Draw.FillOval (ball2x - 1, 245, 30, 30, white)
            ball2x:=ball2x-1
            exit when ball2x=54
        end loop
    end loop
end Ball_2

process collision
    loop
        locate (3, 4)
        put "Collisions:", collisions : 3
        if ball1y + 30 = ball2x + 30 then
            collisions := collisions + 1
            delay (2000)
            View.Update
        end if
    end loop
end collision

fork Ball_1
fork Ball_2
fork collision

loop
    %Bottom Horizontal
    for b : 1 .. 27
        Draw.FillBox (0, 0, 20, 20, Rand.Int (1, 60))
        Draw.FillBox (b * 25, 0, (b * 25) + 20, 20, Rand.Int (1, 60))
    end for

    %Top Horizontal
    for t : 1 .. 27
        Draw.FillBox (0, 375, 20, 395, Rand.Int (1, 60))
        Draw.FillBox (t * 25, 375, (t * 25) + 20, 395, Rand.Int (1, 60))
    end for

    %Left Vertical
    for l : 1 .. 14
        Draw.FillBox (0, l * 25, 20, (l * 25) + 20, Rand.Int (1, 60))
    end for

    %Right Vertical
    for r : 1 .. 14
        Draw.FillBox (675, r * 25, 695, (r * 25) + 20, Rand.Int (1, 60))
    end for
    delay (100)
end loop
shorthair




PostPosted: Thu Jan 15, 2004 7:27 pm   Post subject: (No subject)

TRACE your program , i garuntee you wil lfind your problem , this is when trace becomes very handy.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 19 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: