top of page

Pong Clone

Details

Project Type: Skills Development & Learning

Engine/Language/Software: C++, Visual Studio Code, Raylib

Download Game - GitHub Repository

Images

About

Project 1 in the C++ Fundamentals: Game Programming For Beginners course on GameDev.tv, Axe Game, gave me a good understanding of some of the fundamentals for C++ and Raylib, so before going further with the course I decided to challenge myself and create a clone of Pong.

Below you can see Axe Game, and its final code (click here for repository).

axe_game_rUu4hA9tx7.gif

As seen, Axe Game was still a far cry from being Pong, although I had the beginnings.

I started by taking player control from the blue circle and getting it to move horizontally, much like the red square was already moving vertically. I then reversed this for the red square, by giving the player control of it. Next I elongated the square so it more resembled a paddle and placed it at the edge of the screen, and then created a copy on the other side using different controls so a different player could play as it.

The next few things that needed doing was making sure the circle would bounce off the paddles when it hit them, done by reversing the x direction. I also added vertical movement to the circle here, which would be dependant on where on the paddle it hit - doing this meant I also had to make sure it would bounce from the top and the bottom of the window.

With all that being done, I had a working version Pong, so I added a few finishing touches which included a scoreboard and a game over screen, stating which player won when one got to a score of 3, and from here the game could be restarted by pressing R.

After completing the rest of the C++ Fundamentals: Game Programming For Beginners course, I had learnt of a lot more C++ techniques and even functions that Raylib had built in, so I knew I could come back and improve this project even further.

The first thing I did was roll out the ball and the paddles into their own classes.

After this, my next goal was to add a Main Menu with the option to chose to play a future planned mode against AI.

 

For this I created a Scenes system, where each had a integer identifier, and each Scene's tick() function would return the integer for the intended Scene - its own ID if there was no change, and the ID of another Scene if there was. Then in the main() function of the game I used a switch statement using the target Scene ID, which would run the correct scenes tick() function.

Finally, I worked on the AI mode - for this I simply created a new Paddle class and removed the input controls from its tick() function, and instead replaced it with a continuous lerp to the Y position of the ball. This was then scaled by a difficulty factor.

bottom of page