
-----------------------------------
upthescale
Sat Apr 01, 2006 6:57 pm

Pong
-----------------------------------
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

-----------------------------------
do_pete
Sat Apr 01, 2006 7:00 pm


-----------------------------------
You would multiply your X speed variable by -1

-----------------------------------
upthescale
Sat Apr 01, 2006 7:01 pm


-----------------------------------
can u make a program quicktime of a ball bouncing randomoy arond the screen?

-----------------------------------
Cervantes
Sat Apr 01, 2006 7:02 pm


-----------------------------------
"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.


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
Sat Apr 01, 2006 7:04 pm


-----------------------------------
Huh? What are you trying to say?

-----------------------------------
upthescale
Sat Apr 01, 2006 7:06 pm


-----------------------------------
doesn't werk



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
Sat Apr 01, 2006 7:13 pm


-----------------------------------
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
Sat Apr 01, 2006 7:14 pm


-----------------------------------
i've been trying fer weeks now can u plz just fix it and paste it

-----------------------------------
do_pete
Sat Apr 01, 2006 7:18 pm


-----------------------------------
We don't do people's homework

-----------------------------------
upthescale
Sat Apr 01, 2006 7:20 pm


-----------------------------------
im done turing i finished it last semester

-----------------------------------
Cervantes
Sat Apr 01, 2006 7:33 pm


-----------------------------------
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
Sat Apr 01, 2006 7:34 pm


-----------------------------------
but when i puty x:=-x like u told me, the box just stays n the same position ttwitching like a mad man

-----------------------------------
[Gandalf]
Sat Apr 01, 2006 7:55 pm


-----------------------------------
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.
