Pong

Pong was of the first video arcade games ever created, developed by Atari in 1972. This took over three months of development as the original game was created on a physical circuit, instead of as a virtual program. Today I am going to see how long it would take to program this game from scratch using java on the Processing IDE; which can be downloaded here at https://processing.org .

After creating a new project, I immediately began to work on the background for the game. The original game features a dotted line going down the middle of the screen, and two scores on each side. Luckily this was much easier to program than it would have been to build as a circuit. Apart from a few huge rectangles here and there, this only took about 5 minutes.

Game background

As we can see here, I also added two white rectangles at the top and bottom of the screen to indicate the boundaries.

The next thing to do was to program the ball. The ball is fired from the center in a random direction at a random speed and accelerates as the rally continues. To add to the difficulty of the game, I added a property so that the ball fires off at a random speed as well.

Pong ball firing randomly

The ball object was built and would reset its position when it reaches the horizontal boundaries and bounce when it reaches the vertical ones. It then changes speed and direction during the reset. I accidentally left this program running for an hour and got the scores up to around 900 each. Surprisingly there was only a difference of around 10 between them.

Now the last part to add was the player and the opponent. To keep this simple and as Processing doesn’t like it when you press more than one key at a time, one paddle had to be the computer.

The paddles themselves were not too difficult to make, being simple rectangles. Adding the bounce mechanic was surprisingly easy, only generally requiring the x-velocity to change sign when touching a paddle. This does lead to some issues, like the ball having a seizure inside your paddle, if the ball goes in from the top or bottom. All in all could have been worse.

Me losing very obviously deliberately

The actual intelligence of this AI makes a potato look like Einstein. Literally all it does is check where the ball is and try to get to that point. I could try make it more sophisticated but for now this is fine. The difficulty can be increased by increasing the max distance the computers paddle can travel per given frame.

So this took about two hours to make, although I did not do it in one sitting. And there we have it, a nice home version of pong that brought a tear to my Dad’s eye as he remembers fondly playing this game at an arcade near his house.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.