Trying to make a pong game. Please help!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Guest

Trying to make a pong game. Please help!

Post by Guest » Wed Jan 18, 2006 4:51 pm

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.

User avatar
Xerol
Veteran
Posts: 81
Joined: Tue Jan 04, 2005 6:27 pm
Location: Timonium, MD
Contact:

Post by Xerol » Thu Jan 19, 2006 2:24 am

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).
If you need music composed in MP3, WAV, or MIDI format, please contact me via email.

Xerol's Music - Updated Regularly!

User avatar
Deleter
Veteran
Posts: 119
Joined: Sat May 07, 2005 7:31 pm

Post by Deleter » Thu Jan 19, 2006 3:34 pm

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

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} » Fri Jan 20, 2006 3:03 pm

I agree with deleter. I used POINT for my first pong clone, and results weren't very pretty...
Image

User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm
Contact:

Post by Zamaster » Thu Jan 26, 2006 7:18 pm

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?
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN

Post Reply