Advertisement

pong

Started by December 16, 2002 07:58 PM
20 comments, last by craphead 21 years, 10 months ago
im making pong in sdl i need to make the ball bounce and move by itself. Cone3d doesnt have anything and the way gamedev does bouncing doesnt work with me. "thats ho i got into my last mess" shuv-it
50/50 Robotics and Software
To make it move by itself, you have to have an x and y velocity. Each frame increase x by x_velocity and y by y_velocity. If it hits a wall, you bounce it by negating one of the velocities. If it hits the top or bottom, then y_velocity = y_velocity * -1. If it hits the paddle, there are two ways you can do it. Either the lazy way, and just negate the x velocity, or the better way: set the new x and y velocity depending on where you hit on the paddle. If this is your first time programming pong, I suggest the lazy way.


- f l u c k y p o o
- f l u c k y p o o
Advertisement
that doesnt work

shuv-it
50/50 Robotics and Software
quote: Original post by craphead
that doesnt work

shuv-it


You have to elaborate on your problem. I''ve programmed pong before, so I know that does work. In games, if you want something to be moving even when the user isn''t inputting anything, you use velocity. I could write comprehensive instructions in telling you exactly how to program pong, but then you wouldn''t be programming pong, I would. If you need help though, feel free to ask specific questions.


- f l u c k y p o o
- f l u c k y p o o
It should work. Do you have something like this when you update:

ball.pos.x += ball.vec.x;
ball.pos.y += ball.vec.y;

And something like this when you start:

ball.vec.x = 1;
ball.vec.y = 1;

So that it's moving from the start?

The only other thing I can see you messing up is accidently swapping < with > or x with y.

[edited by - smart_idiot on December 16, 2002 11:29:49 PM]
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Here ... I am trying to make pong also. Will someone program it for me so I don''t have to think about things?



_______________________________
It''s not reality that''s important, but how you perceive things.

A man''s reach should exceed his grasp.
Advertisement
quote: Original post by craphead
that doesnt work

shuv-it

Then you''re doing it wrong.

A more detailed problem description (and in a case such as this, some sample source code) would help people pinpoint what exactly you are doing wrong.
quote: Original post by The Reindeer Effect
Here ... I am trying to make pong also. Will someone program it for me so I don''t have to think about things?



_______________________________
It''s not reality that''s important, but how you perceive things.

A man''s reach should exceed his grasp.


sure
email me at sexybastardREMOVE@xtra.co.nz + ill email + a pong version



http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html

     int count=0;  if(count==0)  {bplus:  by += 2;  bx += 2;  if(bx==800)  {goto bminus;}  if(by==600)  {goto bminus;}  goto bplus;  bminus:  by -= 2;  bx -= 2;  if(bx==0)  {count +=1;  goto bplus;}  if(by==0)  {count +=1;  goto bplus;}  goto bminus;}   if(count==1)  {plus:  by += 2;  bx += 2;  if(bx==800)  {goto minus;}  if(by==600)  {goto minus;}  goto plus;  minus:  by -= 2;  bx -= 2;  if(bx==0)  {count +=1;  goto plus;}  if(by==0)  {count +=1;  goto plus;}  goto minus;}  if(count==2)  {aplus:  by += 2;  bx -= 2;  if(bx==800)  {goto aminus;}  if(by==600)  {goto aminus;}  goto aplus;  aminus:  by -= 2;  bx += 2;  if(bx==0)  {count +=1;  goto aplus;}  if(by==0)  {count +=1;  goto aplus;}  goto aminus;}  if(count==3)  {cplus:  by -= 2;  bx += 2;  if(bx==800)  {goto cminus;}  if(by==600)  {goto cminus;}  goto cplus;  minus:  by += 2;  bx -= 2;  if(bx==0)  {count +=1;  goto cplus;}  if(by==0)  {count +=1;  goto cplus;}  goto cminus;}  if(count>3)  {count=0}    

this is the problem that freezez my program. i should get a bouncing ball but no.
(bx and by are the coordinates of the ball.)


shuv-it

[edited by - craphead on December 20, 2002 3:57:57 PM]
50/50 Robotics and Software
AHHAA!!!!

That''s a pretty scary piece of code.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement