Jump to content
  • Advertisement
Sign in to follow this  
truthS

.

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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++;
}
else
if( 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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!