
-----------------------------------
Azzy
Tue Jan 13, 2004 4:20 pm

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

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


-----------------------------------
Tony
Tue Jan 13, 2004 4:24 pm


-----------------------------------
you forgot to clear the ball...  :? you ether draw a white one on top of the ball or just use cls to clear the entire screen.

-----------------------------------
Azzy
Tue Jan 13, 2004 4:29 pm


-----------------------------------
Sweet.Thanks.Now for step 3.Make a ball going from left to right.

-----------------------------------
Cervantes
Tue Jan 13, 2004 4:32 pm


-----------------------------------
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
Wed Jan 14, 2004 4:09 pm


-----------------------------------
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
Wed Jan 14, 2004 4:29 pm


-----------------------------------
if ball1x = ball2x and ball1y = ball2y then
count := count +1
end if

-----------------------------------
Azzy
Wed Jan 14, 2004 9:12 pm


-----------------------------------
that does help a bit but i need it so even if it touches the ball at the rim it counts it.

-----------------------------------
Cervantes
Wed Jan 14, 2004 9:34 pm


-----------------------------------
well are you going to make the balls bounce apart??  that would be super hard to do right (as I just found out recently :P)

if not then what shorthair said will do it

-----------------------------------
Azzy
Wed Jan 14, 2004 9:35 pm


-----------------------------------
well...actually.that's part 5 and 6.5 is just it going backwards.easy.while 6 is using physics.bouncing everywhere.

-----------------------------------
Cervantes
Wed Jan 14, 2004 9:42 pm


-----------------------------------
well if they aren't going to pass through each other then you could always use whatdotcolor to solve your worries :P

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
Thu Jan 15, 2004 4:40 pm


-----------------------------------
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
Thu Jan 15, 2004 5:02 pm


-----------------------------------
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
Thu Jan 15, 2004 5:11 pm


-----------------------------------
bouncing apart...would be something like this(i think)

if ballx=ballx2 and bally=bally2 then
ballxdir:=-ballxdir
ballydir:=-ballydir
end if

-----------------------------------
Azzy
Thu Jan 15, 2004 5:21 pm


-----------------------------------
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.

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
Thu Jan 15, 2004 7:27 pm


-----------------------------------
TRACE your program , i garuntee you wil lfind your problem , this is when trace becomes very handy.

-----------------------------------
Hunter007
Sat Jan 17, 2004 8:31 pm


-----------------------------------
I'm working on the same program and I have a problem. I need to add a collision counter, but the thing is my code is different.


View.Set ("graphics:600;400,offscreenonly") 

var Color : int 
var x1, y1, dx1, dy1, x2, y2, dy2, dx2 : int 

for i : 1 .. maxx by 20 
    Color := Rand.Int (1, 60) 
    if Color = 31 then 
        Color := Rand.Int (1, 60) 
    end if 
    Draw.FillStar (i, 0, i + 20, 20, Color) 
    Draw.FillStar (i, maxy - 20, i + 20, maxy, Color) 
end for 

for k : 20 .. maxy - 20 by 20 
    Color := Rand.Int (1, 60) 
    if Color = 31 then 
        Color := Rand.Int (1, 60) 
    end if 
    Draw.FillStar (0, k, 20, k + 20, Color) 
    Draw.FillStar (maxx - 20, k, maxx, k + 20, Color) 
end for 
x1 := maxx - 40 
y1 := maxy - 60 
x2 := maxy - 40 
y2 := maxy - 40 
dx1 := 2 
dy1 := 0 
dx2 := 0 
dy2 := 2 


loop 
    x1 := x1 + dx1 
    x2 := x2 + dx2 
    y1 := y1 + dy1 
    y2 := y2 + dy2 
    if x1 > maxx - 40 or x1 < 40 then 
        dx1 := -dx1 
    end if 

    if x2 > maxx - 40 or x2 < 40 then 
        dx2 := -dx2 
    end if 
    if y2 > maxy - 40 or y2 < 40 then 
        dy2 := -dy2 
    end if 

    Draw.FillOval (x1, y1, 20, 20, 12) 
    Draw.FillOval (x2, y2, 20, 20, blue) 
    View.Update 
    delay (10) 
    Draw.FillOval (x1, y1, 20, 20, 0) 
    Draw.FillOval (x2, y2, 20, 20, 0) 

end loop




If someone can help me it would be greatly appreciated.

-----------------------------------
Tony
Sat Jan 17, 2004 8:32 pm


-----------------------------------
well you see where you got your dx1 := -dx1  parts in the loop? Thats where your collision occurs and you should increment you counter right after

-----------------------------------
Hunter007
Sat Jan 17, 2004 8:40 pm


-----------------------------------
I'm not sure I understand what you mean.

I tried this:


if dx1 := dx1 and dy1 = dy2 then
    count := count + 1
end if


It didn't work. It said that if must be boolean type.

-----------------------------------
Azzy
Sun Jan 18, 2004 8:27 am


-----------------------------------
you had a colon in the first part of it.that's a no no.

if dx1 = dx1 and dy1 = dy2 then 
    count := count + 1 
end if 

