Page 1 of 1

Trying to make a pong game. Please help!

Posted: Wed Jan 18, 2006 4:51 pm
by Guest
Hello, everyone. I've been working on a remake of Ping Pong. So far I've got the ball moving, the paddles controlled. Now, for your help. I would like to know how can I make the ball bounce in the other direction if it hits the paddle. I was told by a senior to use the point command. I have no clue what/how that works. Please, an explanation on point command will be appericiated.

Posted: Thu Jan 19, 2006 2:24 am
by Xerol
The POINT command returns the color of a point on the screen. So basically if you've got a black background, you could see if the color of the point in front of the ball is black or not, and if not, then bounce the ball. (You need to check in front of the ball and not actually AT the ball because checking the point where the ball is at will always make it bounce, since it'll "see" the ball as an object to bounce off of.)

The basic syntax:

Code: Select all

c = POINT(x,y)
Which returns the color value of the point at (x,y).

Posted: Thu Jan 19, 2006 3:34 pm
by Deleter
you would probably be better off using collision detection with bounding boxes.

something like this:

Code: Select all

if ( ball.y - ball.radius ) < ( paddle.y + paddle.height ) then
    if ( ball.y + ball.radius ) > ( paddle.y ) then

        if ( ball.x - ball.radius ) < ( paddle.x + paddle.width ) then
            ball.xSpeed = -ball.xSpeed
        end if
    end if
end if

Posted: Fri Jan 20, 2006 3:03 pm
by {Nathan}
I agree with deleter. I used POINT for my first pong clone, and results weren't very pretty...

Posted: Thu Jan 26, 2006 7:18 pm
by Zamaster
Or, you might want to try something a bit different for collision detection. Deleter's way works just fine for most situations... but in some instances it can cause the ball to vibrate madly back and forth inside the object its colliding with. I dont feel like coding anythnig right now, but think in terms of... ill say "collision paths". Instead of just checking to see if your inside an object, check to see if your next move is gonna hit the paddle and if it does, place the ball on the paddle farthest away from the center of the paddle while keeping the ball in the collision path. Its sounds confusing, but Ill let other people get in depth with it. This way, ever if you over shoot the paddle cause your moving so fast, the ball wont get stuck inside but will bounce directly off the surface. A little bit of interesecting line math is needed for this one and some fairly tricky logic. Did I make any sense?