This is a pong clone written in c++ and SDL2. This is my first real project with SDL2 or even c++, so please excuse that the code is quite stinky.
This game is unfortunately local multiplayer only : once you press P
in the main menu to play, the left player controls their paddle up and down movement with W
and S
, while the player on the right can use the up
and down
arrows or O
and L
keys.
here is the pre built binary for windows
To compile this you will need to download
- SDL2 development library
- SDL2_mixer development library
First, clone the repository
$ git clone --depth 1 https://github.com/Dr-McFish/SDL2-Pong.git SDL2-Pong && cd SDL2-Pong
Compile with with the following flags:
-std=c++17
-O3
-Wall
-m64
-I include
-o game.exe
-lSDL2main
-lSDL2
-lSDL2_image
-lSDL2_mixer
On Windows, also use
-mwindows
-lmingw32
Note: You may need to indicate the include paths for the SDL2 and SDL2_mixer dependencies using the -I <dirname>
flag, as well as the lib/linker directory using -L <dirname>
flag.
Note: for some god forsaken reason SDL2_mixer expects you to include
.../sdl2_folder/include/SDL2/
instead of
.../sdl2_folder/include/
so you have to include both.
For example, the command may look like something like this:
$ g++ src/*.cpp -std=c++17 -O3 -Wall -m64 -I include -I <SDL2 include folder> -I <SDL2mixer include folder> -o game.exe -mwindows -L <SDL2 lib folder> -L <MinGW-w64 lib folder> -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer
To run the game, runtime libraries need to be be present inside the folder of the executable
Coppy all the .dll
s from the .../SDL2/bin/
and .../SDL2_mixer/bin/
into the current folder.
If you want to delete the source files / move the executable to another location, note that the res/
folder is needed for the game to function.
Enjoy!
- Thanks to codergopher, who's YouTube series for being helpful on this topic,
- All dlls in the binary folder are not my own, I am only redistributing them, they are part of the SDL2 project