Computer Science Canada Problem Bouncing |
| Author: | TokenHerbz [ Thu Jul 21, 2005 10:02 pm ] |
| Post subject: | Problem Bouncing |
Hi, i read all the totorials, believe you me, and maybe i dont know what its sopposed to be like, and passed it, so sorry if i made you mad. setscreen ("Graphics,500,500") var ballc: array 1 .. 5 of int var ballx: array 1 .. 5 of int var bally: array 1 .. 5 of int var ballx1: array 1 .. 5 of int for i: 1 .. 5 randint(ballc(i),1,99) end for for i: 1 .. 5 randint (ballx(i),100,400) end for for i: 1 .. 5 randint (bally(i),100,400) end for for i: 1 .. 5 randint (ballx1(i),1,10) end for for i: 1 .. 5 drawfilloval (ballx(i),bally(i),ballx1(i),ballx1(i),ballc(i)) end for ------------------------ Thats my code for now, i know how to make boudries OFF the sides, i need help making the balls bounce off each other... Also, i dont know how to make them move in random directions from start, gaining speed each time 1 hits either another ball, or the sides. Im thinking i need a loop AFTER my for statments... but i tryed like for i: 1 .. 5 ballx(i) := ball + 1 end for it dosn't work, i tryed more, nothings random, and i just need some help trying to understand more of this. with the boundries, for i: 1 .. 5 if ballx(i) >= maxx - 10 then ballx(i) := maxx - 10 elsif ballx(i) <= 10 then ballx(i) := 10 end if end for Thats assuming my random ball size is maximum 10, well i think that'll work, either way... Id like help... Over Veiw... To get 5 balls of random speed, size, color, place, etc: moving in random directions gaining speed each time they collide with eachother OR the boundries (Which i want to be set to what ever the user sets the screen too)... I also want to outr ball to hit the end, so maybe we have to add in some Radious??? variables? yes? Anywho, to just accomplish all this, Help with explainations and correct code would be much appreciated... I dont want no bunk proceadures at all, i read there crap, so im not going to ever use them. Thanks! |
|
| Author: | TokenHerbz [ Thu Jul 21, 2005 10:12 pm ] |
| Post subject: | |
Um, me again, i notice other peoples code is really small, and blue... how do u do that, cause my big post must bug you guys/girls off... |
|
| Author: | Tony [ Thu Jul 21, 2005 11:28 pm ] |
| Post subject: | |
for "blue" code tags: [code] ... [/code] better yet - "red" syntax [syntax="turing"] ... [/syntax] |
|
| Author: | Cervantes [ Fri Jul 22, 2005 8:29 am ] | ||||
| Post subject: | Re: Problem Bouncing | ||||
tokenherbz wrote: Thats my code for now, i know how to make boudries OFF the sides, i need help making the balls bounce off each other... Making balls bounce off each other is quite difficult. For some source code, check out thoughtful's pool tutorial. For more source code of this in action, check out my Evasive Maneuvers game. Also, I'm not sure what "ballc" and "ballx1" are supposed to be. You should probably be using "ballx", bally", ballvx", and ballvy". The last two represent the velocity in the x and y planes, repsectively.
That won't make the ball bounce off the wall, it will only make the ball stick to the wall. To bounce off, it has to reverse its direction in the plane perpendicular to the wall. Since the wall (two of them, anyway) are in the y plane, we must reverse the velocity in the x plane:
tokenherbz wrote: gaining speed each time they collide with eachother OR the boundries This goes against the laws of physics. If you really want this though, just multiply the velocity of the ball by 1.1 or a number close to but above one each time a collision occurs. Cheers! |
|||||
| Author: | TokenHerbz [ Fri Jul 22, 2005 7:27 pm ] | ||
| Post subject: | |||
this is that i have so far... again
Form setting balls to bounce down, it screws up royaly, take it out, itll go nicly.. I looked over the pool game, and am still stumped... Perhaps just tell me? i cant seem to find it anywhere in the totoreals... Please tell me the fastest, easyist code to acomplish the bouncing of the balls. I just want the balls to bounce off of each other. Thanks |
|||
| Author: | MysticVegeta [ Sat Jul 23, 2005 4:23 pm ] | ||||
| Post subject: | |||||
couple of things. 1> Array declarations shouldnt take more than 1 line. 2> You can randint the 4 things in jsut 1 for loop. No need to make 6 3> So many arrays
And to call a record, its really easy..
|
|||||
| Author: | TokenHerbz [ Sat Jul 23, 2005 9:31 pm ] |
| Post subject: | |
ok, but hows that help my problem? the balls, they don't bounce off of each other. |
|
| Author: | Cervantes [ Mon Jul 25, 2005 8:12 pm ] |
| Post subject: | |
Have you looked at the link I gave you? The one to thoughtful's pool. You'll have to adapt it to your program yourself. tokenherbz wrote: ok, but hows that help my problem? It makes your code more organized, readable, understandable, and therefore better. |
|
| Author: | MysticVegeta [ Tue Jul 26, 2005 6:05 pm ] |
| Post subject: | |
couldnt have said that better myself, Geoff |
|