Pong
Author |
Message |
upthescale
|
Posted: 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> |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
do_pete

|
Posted: Sat Apr 01, 2006 7:00 pm Post subject: (No subject) |
|
|
You would multiply your X speed variable by -1 |
|
|
|
|
 |
upthescale
|
Posted: Sat Apr 01, 2006 7:01 pm Post subject: (No subject) |
|
|
can u make a program quicktime of a ball bouncing randomoy arond the screen? |
|
|
|
|
 |
Cervantes

|
Posted: Sat Apr 01, 2006 7:02 pm Post subject: (No 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.
pseudo: |
If it bounces of a horizontal wall then
reverse the y velocity
else if it bounces off a vertical wall then
reverse the x velocity
end if
|
|
|
|
|
|
 |
do_pete

|
Posted: Sat Apr 01, 2006 7:04 pm Post subject: (No subject) |
|
|
Huh? What are you trying to say? |
|
|
|
|
 |
upthescale
|
Posted: Sat Apr 01, 2006 7:06 pm Post subject: (No subject) |
|
|
doesn't werk
code: |
var x, y : int
randint (x, 1, 500)
randint (y, 1, 200)
loop
drawfillbox (x, y, x + 30, y + 30, 7)
delay (12)
drawfillbox (x, y, x + 30, y + 30, 0)
x := x + 2
y := y + 2
if y > 420 then
exit
end if
end loop
loop
drawfillbox (x, y, x + 30, y + 30, 7)
delay (12)
drawfillbox (x, y, x + 30, y + 30, 0)
x := -x
end loop
|
|
|
|
|
|
 |
Cervantes

|
Posted: Sat Apr 01, 2006 7:13 pm Post subject: (No 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. |
|
|
|
|
 |
upthescale
|
Posted: Sat Apr 01, 2006 7:14 pm Post subject: (No subject) |
|
|
i've been trying fer weeks now can u plz just fix it and paste it |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
do_pete

|
Posted: Sat Apr 01, 2006 7:18 pm Post subject: (No subject) |
|
|
We don't do people's homework |
|
|
|
|
 |
upthescale
|
Posted: Sat Apr 01, 2006 7:20 pm Post subject: (No subject) |
|
|
im done turing i finished it last semester |
|
|
|
|
 |
Cervantes

|
Posted: Sat Apr 01, 2006 7:33 pm Post subject: (No 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. |
|
|
|
|
 |
upthescale
|
Posted: Sat Apr 01, 2006 7:34 pm Post subject: (No subject) |
|
|
but when i puty x:=-x like u told me, the box just stays n the same position ttwitching like a mad man |
|
|
|
|
 |
[Gandalf]

|
Posted: Sat Apr 01, 2006 7:55 pm Post subject: (No 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. |
|
|
|
|
 |
|
|