Computer Science Canada Pong |
Author: | upthescale [ Sat Apr 01, 2006 6:57 pm ] |
Post subject: | Pong |
<h1>i wanna make a pong game, but how do i do it so when the ball withs the edge of the screen, it will bounce away randomly, liek i don't want to set coordinates for the wohle game i want it no random</h1> |
Author: | do_pete [ Sat Apr 01, 2006 7:00 pm ] |
Post subject: | |
You would multiply your X speed variable by -1 |
Author: | upthescale [ Sat Apr 01, 2006 7:01 pm ] |
Post subject: | |
can u make a program quicktime of a ball bouncing randomoy arond the screen? |
Author: | Cervantes [ Sat Apr 01, 2006 7:02 pm ] | ||
Post subject: | |||
"Randomness" can be achieved by using the Rand.Int function. Do you really want it to bounce randomly off a wall, though? That's not how collision works in this universe of ours. It's not random. The angle of incidence equals the angle of reflection. This is most easily achieved if you have x and y components to your ball's position and velocity, and if the wall it is bouncing off of is parallel to either the x or y axis.
|
Author: | do_pete [ Sat Apr 01, 2006 7:04 pm ] |
Post subject: | |
Huh? What are you trying to say? |
Author: | upthescale [ Sat Apr 01, 2006 7:06 pm ] | ||
Post subject: | |||
doesn't werk
|
Author: | Cervantes [ Sat Apr 01, 2006 7:13 pm ] |
Post subject: | |
It works. You've just done it wrong. ![]() Why did you exit your loop when the ball collides with a horizontal wall? That's not what you want to do. You want to reverse it's vertical velocity. Furthermore, in the last portion of your code (the second loop), x := -x is not going to reverse the velocity of the ball. It's going to flip the ball from one side of the y axis to the other. Finally, your code exits the first loop when it bounces off a horizontal wall, then you go in the second loop attempting to modify the horizontal velcoity. The horizontal velocity doesn't change when a ball bounces off a horizontal wall. Really, this isn't hard. Put a little thought into it, and I'm sure you'll understand it a whole lot better. Feeding you the answers isn't going to help you understand anything as much as if you figured it out mostly on your own. |
Author: | upthescale [ Sat Apr 01, 2006 7:14 pm ] |
Post subject: | |
i've been trying fer weeks now can u plz just fix it and paste it |
Author: | do_pete [ Sat Apr 01, 2006 7:18 pm ] |
Post subject: | |
We don't do people's homework |
Author: | upthescale [ Sat Apr 01, 2006 7:20 pm ] |
Post subject: | |
im done turing i finished it last semester |
Author: | Cervantes [ Sat Apr 01, 2006 7:33 pm ] |
Post subject: | |
Trying for weeks, but on what? You've already been told basically how to do it. Begging for people to tell you the answers is a terrible attitude. |
Author: | upthescale [ Sat Apr 01, 2006 7:34 pm ] |
Post subject: | |
but when i puty x:=-x like u told me, the box just stays n the same position ttwitching like a mad man |
Author: | [Gandalf] [ Sat Apr 01, 2006 7:55 pm ] |
Post subject: | |
Create a vx and vy variable (velocity in x direction, velocity in y direction), and work with those instead of directly with the x and y vars. |