Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
Collisions
Author Message
anywho_ya

Posted: 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

Flashkicks

Posted: Wed May 05, 2004 7:54 am   Post subject: (No subject)

I tried to help but we cant use the math.Distance command..
anywho_ya

Posted: 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
anywho_ya

Posted: 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
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 4 Posts ]
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: