This repo houses a cross-platform 2D game engine with built-in multiplayer support. Both client-server and peer-to-peer network architectures are supported. The engine also features an entity component system for constructing game objects, a physics engine, an input system with multi-key chord support, in-game timelines, side-scrolling mechanics, event management, game replay functionality, and profiling with the Tracy profiler.
Pre-built game binaries for Windows, macOS and Ubuntu are available in every release. After downloading the binaries of the latest release for your platform, navigate to the folder containing the game of your choice and run the commands specified below. You may choose between the client-server or peer-to-peer modes. Each command must be run in its own shell. Only a single server or host may be spawned, but you may spawn as many clients or peers as needed.
Client-server mode
./<GAME_BINARY> --mode cs --role server
./<GAME_BINARY> --mode cs --role client
Peer-to-peer mode
./<GAME_BINARY> --mode p2p --role host
./<GAME_BINARY> --mode p2p --role peer
To connect clients or peers with remote servers or hosts, you may specify the following flags
--server_ip
(on clients)--host_ip
and--peer_ip
(on peers)
For more details, refer to the section on engine flags
Client-server mode
5555
: Handles join requests5556
: Broadcasts server updates6000 + x
: For clients to send updates (x
is the client's network ID)
Peer-to-peer mode
5555
: Handles join requests6000 + x
: For peers to broadcast updates (x
is the peer's network ID; the host always hasx = 1
)
Profiled builds
9000
: Streams profiling data to the Tracy profiler
This project uses CMake along with Ninja as the build system
You may install a pre built package of Ninja on your platform
Additionally, please ensure that the following dependencies are installed on your platform
sudo apt update
sudo apt install build-essential x11-apps cmake
Install Homebrew from brew.sh
xcode-select --install
brew install cmake
Install Visual Studio 2022 and choose the Desktop development with C++
workload
Please note that all the Windows commands will need to be run on Developer PowerShell for VS 2022
Fetch dependent libraries and generate build files for your platform
This is a one-time step and need not be done when rebuilding the project
make configure # Ubuntu or macOS
.\scripts\configure.ps1 # Windows 11
Every folder in src/games
maps to a game
The .targetgames
file defines all the games that are supported in the current build
To build all games defined in .targetgames
, run
make # Ubuntu or macOS
.\scripts\build.ps1 # Windows 11
To build a specific game, set the GAME
variable
For example, if these are the games defined in .targetgames
hw5_joshua_homebound
hw5_rohan_space_invaders
hw5_rohan_brick_breaker
And you would like to only build hw5_joshua_homebound
, then you would need to run
make GAME=hw5_joshua_homebound # Ubuntu or macOS
.\scripts\build.ps1 -GAME hw5_joshua_homebound # Windows 11
After a game has been built, you may play it using this command
make play GAME=<game> ARGS="<game_args>" # Ubuntu or macOS
.\scripts\play.ps1 -GAME <game> -GAME_ARGS "<game_args>" # Windows 11
Most games include multi-player support, but require certain flags to be passed to the engine
This is facilitated by the ARGS
variable (GAME_ARGS
on Windows)
The flags supported by the engine are
--mode [single, cs, p2p] (default: single)
--role [server, client, host, peer] (default: client)
--encoding [struct, json] (default: struct)
--server_ip <ip_address> (default: localhost)
--host_ip <ip_address> (default: localhost)
--peer_ip <ip_address> (default: localhost)
To run hw5_joshua_homebound
in the client-server mode, run these commands in different shells
Server
make play GAME=hw5_joshua_homebound ARGS="--mode cs --role server"
Client
make play GAME=hw5_joshua_homebound ARGS="--mode cs --role client"
To run hw5_rohan_space_invaders
in the peer-to-peer mode, run these commands in different shells
Host
make play GAME=hw5_rohan_space_invaders ARGS="--mode p2p --role host"
Peer
make play GAME=hw5_rohan_space_invaders ARGS="--mode p2p --role peer"
To run hw5_rohan_brick_breaker
in the client mode, run the following command
This assumes that the server was already started on the same machine
Client
.\scripts\play.ps1 -GAME hw5_rohan_brick_breaker -GAME_ARGS "--mode cs --role client"
To clear all build artifacts, run
make clean # Ubuntu or macOS
.\scripts\clean.ps1 # Windows 11
More details on setting up the development environment can be found in Development.md
Here is a map of inputs common to every game
Input | Action |
---|---|
p |
Toggle timeline pause |
, |
Slow down the timeline |
. |
Speed up the timeline |
x |
Toggle display scaling |
z |
Toggle hidden zone visibility |
q |
Toggle recording |
r |
Replay the recording |
When made visible, hidden zones are indicated by the following colors
SideBoundary
: BlueSpawnPoint
: GreenDeathZone
: Red
The screen border turns red when recording and blue when replaying
Learn more about each game and its controls in the corresponding
README
files
Please find all references in References.md