Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
bouncing ball??
Author Message
hpdudette

Posted: Thu Jun 05, 2003 3:56 pm   Post subject: bouncing ball??

i'm trying to make this ball bounce in diagonally across the screen but i can't seem to figure out how to make it bounce back or bounce from top to bottom
 code: for x:10..360     drawfilloval (x, x, 30, 30, 4)     delay (5)     drawfilloval (x, x, 30, 30, 0) end for

Posted: Thu Jun 05, 2003 4:08 pm   Post subject: (No subject)

easiest way to do a bouncing ball around the screen is something like this...

 code: const speed := 5 %the ammount the ball is moved const radius := 25 %the radius of the ball var xmove, ymove : int := speed %the amount it moves on the x and y axis var x, y : int %the ball's x and y coordinates on the screen var colr : int := 7 %the colour of the ball %start the ball in the middle of the screen x := maxx div 2 y := maxy div 2 loop     %draw the ball, wait a short time, then draw a white one on top of it     drawfilloval (x, y, radius, radius, colr)     delay (25)     drawfilloval (x, y, radius, radius, 0)     %move the ball's coordinates the respective x and y amounts     x += xmove     y += ymove     if x >= maxx - radius or x <= radius then         %if the middle of the ball (x) is at the edge of the screen         xmove *= -1 %switch the x direction     end if     if y >= maxy - radius or y <= radius then         %if the middle of the ball (y) is at the top of bottom of the screen         ymove *= -1  %switch the y direction     end if end loop
naoki

Posted: Thu Jun 05, 2003 4:28 pm   Post subject: (No subject)

i use something like

if ballx is near 0 or maxx then
xchange := - xchange
end if
if bally is near 0 or maxy then
ychange := ychange
end if
ballx += xchange
bally += ychange

this way only the increment by which you're moving the ball left/right, up/down will change from negative to positive, thus doing all the work for you

Posted: Thu Jun 05, 2003 6:07 pm   Post subject: (No subject)

that's what mine is doing by multiplying it by -1 ..
 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: