This is a simple 2D pong game made in C++ using SDL for rendering and sound. The playable web based version above is a simplified JavaScript port, created using Phaser. The graphics and audio are both created by me, using Aseprite for pixel art and jsfxr for 8-bit sound effects. This game includes 2 modes: an endless mode that uses an impossible AI to see how long you can last, and a 2 player local versus mode that uses arrow keys and WASD to control each side, with the winner being whoever gets to 10 points first.


My game was made in C++ 20 (202002) using visual studio, with SDL2, with its built in mixer, ttf, and image libraries. The game has 4 classes, being Ball, Game, Paddle, and UserInterface. It also has a mainUtils.h and .cpp file, that has useful features such as a vector2 struct, as well as a lerp and inverselerp function, that calculates the linear interpolation and inverse linear interpolation between a min and max value and a value passed into it. Lerp converts a float from 0 to 1 and converts it to be between 2 numbers (0 would be min, 1 would be max), and inverse lerp converts a value between 2 numbers into a float from 0 to 1 (min would be 0, max would be 1).

The source.cpp file holds the main function that’s loaded on start, and creates then runs an instance of the game class.

To make sure the game runs at the same speed regardless of the players framerate, without limiting the framerate of the game so that the player gets the smoothest experience, I set a target fps of 60, and if the game runs higher than that the speed of all game objects slows down to compensate, and if the game runs at a lower fps the speed increases, with a frame speed value multiplying all the speed values such as the ball and paddle.

The game then runs a handleevents function that checks for keypresses and calls the function that the keypresses should call, then it updates every object that needs to be updated in the current scene, then renders all the objects to the screen. The game currently has 3 scenes, scene 0 being the main menu, scene 1 being 2 player, scene 2 being the win / end screen, and scene 3 being the impossible ai mode, and what’s rendered to the screen as well as the text loaded depends on what the value of the int currentScene is. 

Since creating this game in C++ using SDL, I've also created a web port using JavaScript, for a different University module and to make it easier to show off without requiring a download. This JavaScript version uses Phaser to handle the physics and hit-boxes.

This game was created for University assignment, in which I was tasked to create a game in C++ using SDL, that includes AI, different difficulty levels, and multiplayer support. I met this criteria by including an impossible AI along with versus mode, with both being at different difficulties.

The game doesn’t have levels but it does have 2 modes, 2 player, and impossible. A 3rd easy ai mode was intended but I didn’t have enough time or knowledge to implement this mode, but if I were to come back to this game this would be the first thing I would add. The easy ai mode is currently on the menu but won’t load anything since no code is set to run when that option is selected. 

Updated 17 days ago
Published 24 days ago
StatusReleased
PlatformsHTML5, Windows, Linux
AuthorCharlie
Made withPhaser, SDL
Tags2D, Local multiplayer, Multiplayer, No AI, Short, Singleplayer, Versus
Code licenseGNU General Public License v3.0 (GPL)
Average sessionA few minutes
LanguagesEnglish
InputsKeyboard
MultiplayerLocal multiplayer
Player count1 - 2
LinksGitHub

Download

Download NowName your own price

Click download now to get access to the following files:

Pong Linux build.zip 92 kB
Pong Windows build.zip 5.3 MB
Source Code (Github)
External

Leave a comment

Log in with itch.io to leave a comment.