View Full Version : HELP!!!! I need to design Pong!!
09-23-2003, 08:16 PM
I'm a first time user of opengl and C++ and I'm trying to design Pong but guess what, don't know where to start. I haven't had much luck with getting sample programs that'll assist me in this design. Can someone recommend any sites,literature that may be useful and helpful to first time users like me, and where I can source good sample programs. NB: I'm not a CS major.
09-23-2003, 09:35 PM
Turns out it's a common assignment.
Take a look at:
Look under the link to old assignments.
09-24-2003, 01:17 PM
hey thanks cg-hci_novice, your help is much appreciated http://www.opengl.org/discussion_boards/ubb/smile.gif
09-24-2003, 02:32 PM
I think your biggest challenge will be the collision detection between the paddle and ball so get the basics done first and save that step till later on.
09-24-2003, 06:30 PM
Before diving in the code, think about how a pong game works. Put 2 blocks and a ball on your mouse carpet if you have to, and visualize how the game plays. Imagine every object having a point (their middle) and a width/height. From that you can easily figure out (if you have some logic :P ) how you would code the collision detection.
Input is easy, read a tutorial on simple win32 input, dont bother with directX or whatever for now. When your up key is pressed, for example, just add to the y value of your paddle object something like that paddle.y+=SPEED_CONSTANT * deltaTime;
You WILL want to obtain the deltaTime (read up google, "deltaTime, getTickCount") so that you have time-based movement, so that the game will run at the same speed on all computers.
Once you can move your left paddle, for example, just do the same for the other one with 2 other keys.
What really helped me out with making a pong game is drawing the pong game on a 2d geometry paper, then adding in x,y value for each of the object boundaries.
Finally, use ortho mode for your first game. You can draw all objects in screen coordinate instead of world coordinates, it will be much easier to manage.
Hope this helps...
[This message has been edited by dopeflow (edited 09-24-2003).]
09-24-2003, 06:53 PM
If you want a pong source, check out my website www.gdev.org (http://www.gdev.org) (my domain expires soon so the address wont hold long), in coding section under "Bombtrix".
09-25-2003, 10:36 AM
Many thanks DopeFlow and cg-hci_novice,
I got the paddles moving the 'easy way' i.e. idle callback fct but my guess is that I may want to use the Timer function instead because when I move one paddle the other stops. How do I go about it?
I'm also trying to get the ball moving and that seems to be challenge i.e. collision detection.
09-25-2003, 02:10 PM
Uhhh i just remembered, my bombtrix game is a tetris game LOL :P I also made a pong game just before that one but the source isnt on the site, maybe ill post it. Sorry for the bad info :P
09-25-2003, 02:25 PM
So I noticed, i thought I missed something or I just couldn't get to the correct links.
09-25-2003, 02:56 PM
In the update function you'll need code like the following (perhaps repeated for diff cases):
// Case 1: Ball going right
if ((horizontal_ball_direction == 1) && (vertical_ball_direction == 0))
if ((x_ball_up_l+ball_width) >= RIGHT_EDGE)
horizontal_ball_direction = -horizontal_ball_direction;
x_ball_up_l = x_ball_up_l + (horizontal_ball_velocity*horizontal_ball_directio n);
I basically used the shell given on that site. Also, didn't need to support 2 paddles. Sorry.
Hope this helps some.
09-25-2003, 04:23 PM
OHHH I SEEE!!!!
Yeah, I've got the bouncing based on the direction working.I was having a little problem with the logic behind setting and assigning the ball direction.Man,I won't forget these days when i finally become a pro..lol
09-26-2003, 03:13 PM
You may also want to check out pong3d.c in the GLFW (http://hem.passagen.se/opengl/glfw) distribution (based on GLFW, not GLUT, but...). The entire program is 844 lines of C.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.