Computer Science Canada Collisions |
Author: | anywho_ya [ Tue May 04, 2004 8:28 pm ] |
Post subject: | Collisions |
K heres my code ... i need the gravity ball to be able to hit the other moving balls View.Set ("offscreenonly") var x, y : real var vx, vy : real x := maxx div 2 y := maxy div 2 vx := 0 vy := 0.02 var mx, my, mb : int const gravity := 0.02 var font1, font2 : int var timeRunning : int timeRunning := Time.Elapsed var sx, sy : array 1 .. 5 of real var vsx, vsy : array 1 .. 5 of real for i : 1 .. 5 sx (i) := Rand.Int (-maxx, 0) sy (i) := Rand.Int (0, maxy) vsx (i) := 1 vsy (i) := 0 end for loop Mouse.Where (mx, my, mb) x += vx y += vy vy -= gravity if mb = 1 then vy += 0.2 end if cls drawfillbox (0, 10, maxx, maxy - 10, 120) drawfillbox (0, maxy, maxx, maxy - 10, 127) drawfillbox (0, 0, maxx, 10, 127) drawfilloval (round (x), round (y), 5, 5, black) for i : 1 .. 5 sx (i) += vsx (i) sy (i) += vsy (i) drawfilloval (round (sx (i)), round (sy (i)), 10, 10, 42) if (sx (i) > maxx) then sx (i) := Rand.Int (-maxx, 0) sy (i) := Rand.Int (0, maxy) end if exit when y < 15 or y > maxy - 15 or Math.Distance (x, y, sx (i), sy (i)) < (5 + 5) end for View.Update delay (10) exit when y < 15 or y > maxy - 15 end loop |
Author: | Flashkicks [ Wed May 05, 2004 7:54 am ] |
Post subject: | |
I tried to help but we cant use the math.Distance command.. |
Author: | anywho_ya [ Wed May 05, 2004 1:54 pm ] |
Post subject: | thx |
thx anyway ... i'll keep trying though ... something is wrong with the (i) in the exit when statement ... it says i has not been declared |
Author: | anywho_ya [ Wed May 05, 2004 4:19 pm ] |
Post subject: | Figured it out!! |
Ok i have figured it out ... i needed to make a boolean statement in the for and exit there and then exit with the loop as well so basically ... var exitFlag : boolean loop for i : 1 .. 5 sx (i) += vsx (i) sy (i) += vsy (i) drawfilloval (round (sx (i)), round (sy (i)), r2, r2, 42) if (sx (i) > maxx) then sx (i) := Rand.Int (-maxx, 0) sy (i) := Rand.Int (0, maxy) end if exitFlag := Math.Distance (x, y, sx (i), sy (i)) < (r1 + r2) exit when exitFlag end for exit when exitFlag end loop % thats to replace the for and exit when statements thx for ur help |