Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
help needed!
Author Message
gamer

Posted: Fri Apr 09, 2004 4:02 pm   Post subject: help needed!

hi all here i hav a little program with bouncing two balls plus a square in the middle to "block" the balls

questions:
1. if u let the program run for awhile, u'll notice that when the ball hits the square at the corner, the ball does weird things (ex. sliding along the square).......why is this happenin?? how can i fix it?
2. noticing that both balls go at same speed (-2), is it possible if i want to hav one ball go at a random speed?
3. do i just use math.distance for the two bals to bounce off each other?

thnx

Paul

Posted: Fri Apr 09, 2004 4:08 pm   Post subject: (No subject)

the reason for that is the ball isn't bouncing off the edge of the square properly, I had the same problem in paddleball. I didn't take a close look at the code but there could be some possiblilities:
1. the code only checks for the most up, left, down right, coordinates of the ball, so when the ball comes towards the square's corner diagonally, it doesn't detect the collision at all.
2. the collision checks for coordinates that are bypassed because of the large increments of the coordinates of the ball. IE: the wall is at 230, the ball checks for 229, doesn't detect anything, the ball moves 5 forward, checks for 234, and misses the wall.
I dunno how to fix it, because I haven't learned that complex equation that zylum was going to explain.
gamer

Posted: Fri Apr 09, 2004 4:35 pm   Post subject: (No subject)

thnx paul, after i looked at ur 2nd suggestion i tried changing the speed of the ball to 1 instead of 2.... and everythin was fine!!

however, remember i had the other problem of wanting one ball to move at random speed (ie: speed of 1 for 2 seconds then speed of 3 for 2 seconds etc)....so would it stil work?? n how?
Paul

Posted: Fri Apr 09, 2004 4:41 pm   Post subject: (No subject)

it would be weird? I mean you want it to suddenly speed up while it's bouncing?
the you just go like
 code: %incX and incY are the variables that hold the values by which your ball %increases each time of the loop. if incX > 0 then randint (incX, 1, 5) else randint (incX, 1, 5) incX:= -incX end if if incY>0 then incY:=incX else incY:= -incX end if

or are you asking for the ball to bouce off at random angles as it hits the walls? that could be a little more complicated.
gamer

Posted: Fri Apr 09, 2004 4:48 pm   Post subject: (No subject)

no no no....like 4get the collision for a sec....what i need is one ball travel at a varying pace/speed

so if normally it goes at speed of 1, then one or two sec later it goes faster OR slower......n continues

but if talking about collision of the obstacle's corner, i think i must need the speed to be 1.....then maybe i can random the delay? lol but then delay applies for both of the balls, n i need just one ball to be delay, how can i do this??
Paul

Posted: Fri Apr 09, 2004 4:54 pm   Post subject: (No subject)

so one ball travels at a constant speed, the other speed varies.
Maybe have a counter inside the loop, and have the 2 balls increase by 2 different variables, when the counter counts that the loop has run say, 10 times, it changes the increase variable from 1 to 3, then after it runs another 10 times, it changes to 2, so just randint inside the loop? I dunno about the delay thing though. It could probably mess up your collision detection too.
gamer

Posted: Fri Apr 09, 2004 5:27 pm   Post subject: (No subject)

damn even tho i change the speed to 1 the corner detection would screwup if i let the program run longer.....i guess this isnt the way to fix it
wut should i do then?
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 1  [ 7 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: