Public Group

# .

This topic is 4840 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

. [Edited by - truthS on August 20, 2005 3:19:46 PM]

##### Share on other sites
I'm too currently making a pong clone but I haven't looked around much for tutorials. Pong is probably the esiest game you can make, which is a good start. If you think about it, there isn't much stuff to do actually. Graphics wise, all you need to be able to do is show a bitmap at position x,y on screen. That should be quickly done with SDL, they've got a bunch of tutorials for that. Then you'll need to react to the keybard, but SDL is painless there and the tuts on their page are great.

But for the sake of curtosy, I'll jot down what I did for my pong game.

When the player presses up, move paddle up. The same for down. Currently I don't have AI.

The ball itself has a position (x,y), speed (s) and direction (x,y). For simplicitly I multiply speed with direction to get velocity. This is the value "movement in a direction per second". Every frame I call update and pass the seconds passed since last update.
ball.position += ball.velocity * secsSinceLastUpdate;

That should be fairly easy. Now the ball needs to bounce. The upper and lower walls are easy.

if( ball.position.y > upperWall.y  ||  ball.position.y < lowerWall.y ) // outside arena  ball.velocity.y = -ball.velocity.y;

You could set the ball.position to something inside the play area when you hit the wall. Because if the ball passes the wall and you just flip the velocity, it will still be outside and thus infinitly go inside that if() statement that switches the velocity.

Now, the last part. Hitting the paddles. The paddles could have a position and speed, as well as a length. And making it easy, if the ball misses the paddle then the other player scored.

if( ball.position.x < player1.position.x ) // in player 1's goal area{  if( ball.position.y < player1.position.y  ||  ball.position.y > player1.position.y+player1.length ) // Hit!    ball.velocity.x = -ball.velocity.x;  else // Miss!    player2.score++;}elseif( ball.position.x > player2.position.x ) // in player 2's goal area{  if( ball.position.y < player2.position.y  ||  ball.position.y > player2.position.y+player2.length ) // Hit!    ball.velocity.x = -ball.velocity.x;  else // Miss!    player1.score++;}

This has the same collision problem as the wall. But ignore that for now, just make this thing run! ;)

Note: For simplicitly I ignored the fact that the ball has a radius. I'll leave that as an excersice, but don't get discouraged - try this first and you should see where the radius should be used.
Also, you might want to refactor this when it's done.

##### Share on other sites
I think you may be getting a bit ahead of yourself if you feel you need to be spoonfed everything. Go back to basics. Find a simple C++ book and do the exercises. Write a simple guess the number game. Write a simple console based address book. Do these simple projects, and work out the logic and code yourself as much as possible. The only way you are going to learn to represent ideas in code is through practice.

##### Share on other sites
GameDev's own Aaron Cox has some nice SDL Tutorials which, in my opinion, are infinately better then the ones provided by Cone3D.

##### Share on other sites
Np =)

I don't have a silver bullet answer. But all I did was think a bit. My personality makes me overcomplicate everything, so what I wrote above is what I could be bothered with when implementing my own Pong game. You could complicate Pong into infinity, or at least I can =P I just played a few Pong games and tried to figure out what they did.

Maybe you could practice this by becoming a bit better at C++ doing hangman games etc. (pure text logic and no physics+graphics+etc.) and on the side play around with pen and paper trying to figure out what exactly happens in a game of Breakout or Tetris.

Cheers!
/JP

1. 1
Rutin
22
2. 2
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633307
• Total Posts
3011288
• ### Who's Online (See full list)

There are no registered users currently online

×