A 2D platformer and the custom C++ game engine it runs on, built with SFML on an entity-component-system architecture.
Overview
Galactic Ink is a 2D platformer where you play as a space squid fighting through levels themed after the planets, from Mercury out to Neptune. Under the hood it’s a small game engine written from scratch in C++: scenes, an entity-component-system, a physics and collision system, frame-based sprite animation, raycast line-of-sight for enemies, and a full in-game level editor built with Dear ImGui.
Every sprite and animation in the game is hand-drawn.
Table of Contents
Features
- Custom engine: a game object that owns and switches between scenes, each running its own ordered set of systems every frame
- Entity-component-system: entities are composed from components (transform, bounding box, gravity, health, animation, state, raycast, and more) instead of deep inheritance
- Platforming movement: running, jumping and gravity, with distinct grounded and aerial states
- Physical interaction: push boxes, pick them up, carry them while jumping, and throw them
- Combat: a melee attack and two directions of ink projectiles
- Enemies with line of sight: enemies cast rays against the level geometry to tell whether they can actually see the player
- Hand-drawn animation: sprite-sheet animations for every player and enemy state, plus particle effects like dust clouds and landing puffs
- Data-driven levels: every level is a plain text file describing what to spawn and where
- Built-in level editor: place, move and scale tiles, enemies and decorations in an ImGui editor, then save and play your level from the main menu
- Debug views: toggle textures, collision boxes, the tile grid, raycasts and an FPS counter at runtime
Architecture
Game
Game owns the SFML window, the asset store and every scene. It runs the main loop at a fixed 60 FPS, turns keyboard and mouse events into named Actions (each scene registers which keys map to which action names), and hands control to whichever scene is current.
Scenes
Every scene inherits from an abstract Scene base with its own EntityManager, its own action map, and update(), sDoAction() and sRender() methods. Switching scenes is just swapping which entry in the scene map is current, so the menu, the game and the editor are completely independent of each other.
Entities and components
An Entity is an id, a tag and a fixed set of component slots, stored as a std::tuple of every component type. Each component carries an exists flag, so entity->has<CGravity>() and entity->get<CTransform>() are compile-time template lookups rather than map searches or casts.
| Component | Purpose |
|---|---|
CTransform |
Position, previous position, velocity, scale, rotation |
CBoundingBox |
Collision box and invincibility frames |
CGravity |
Per-entity gravity strength |
CInput |
Current input state for the player |
CState |
Movement, aerial and combat state (as enums) |
CAnimation |
The active animation and whether it loops |
CHealth |
Health and hearts |
CRayCast |
Line-of-sight rays and vision cone for enemies |
CLifespan |
Auto-destroy after a number of frames (projectiles, particles) |
CMovePoints |
Waypoints for moving objects, set in the editor |
CText, CUserInterface |
On-screen text and HUD elements |
The EntityManager
The EntityManager keeps every entity in one vector, plus a map from tag to entities so a system can grab “all enemies” or “all tiles” without scanning everything. New entities are queued and only added at the start of the next frame, and destroyed entities are removed at the same point, so no system ever modifies the list it’s iterating over.
Systems and the game loop
Each frame, Scene_Play::update() runs its systems in a fixed order:
- Input: read input and update the player’s
CInput - GUI: the debug window
- Movement: apply input, gravity and velocity; pushing, carrying and throwing boxes
- Animation: advance every entity’s animation and pick the right one for its current state
- Lifespan: destroy entities whose time is up
- Raycasting: update enemy line of sight
- Render: draw the frame
- Collision: resolve overlaps between entities
Collision uses axis-aligned bounding boxes. Comparing the overlap this frame with the overlap from the previous frame tells the engine which side a collision came from, so the player lands on top of a block instead of being pushed through its side.
States like running, jumping, pushing or holding a box are enums rather than strings. With many moving boxes on screen, comparing strings every frame became a real cost, and switching to enums fixed it.
Animation
Each animation is a horizontal sprite strip. An Animation knows how many frames the strip holds and how many game frames to show each one for, and advances the sprite’s texture rectangle across the strip, looping or stopping at the end.
Levels
Levels are plain text files, one object per line, with positions in 64×64 grid units:
DecBG MainMenuBG
Player 3 5 64 64 2 2 10 18 3 1.3 5
Enemy 15 7 256 256 4 4 8 24 150 TallMushroom TallIdleSleep
Tile Dirt 0 1 2 2 0
This follows the type of `TYPE GRIDX, GRIDY, CX, CY, SCALEX, SCALEY, SPEED, MAXSPEED, JUMP, GRAVITY, HEARTS;’ for the player, other times like the enemy might include things like the sprite and then the animation type and other things of that nature.
Scene_Play reads the file and spawns each entity with the components its type needs. The player and enemy lines also carry their configuration (size, speed, jump strength, gravity, health), so tuning a level never needs a recompile.
The Level Editor
Scene_Create is a full level editor built with Dear ImGui. Pick a sprite from the sprite tab (hovering shows a preview), click to place it on the grid, and adjust its scale and properties from the panel. Moving objects get waypoints placed directly in the level. Levels are saved as the same text format the game reads, and saved levels show up in the main menu, ready to play.
Editor controls: mouse wheel to zoom, hold right-click and move to pan, G to toggle the grid, Esc to return to the menu. A built-in guide tab explains the rest.
Controls
| Key | Action |
|---|---|
A / D |
Move left / right |
W |
Jump |
Left Shift |
Run |
Left Click |
Melee attack |
Right Click |
Shoot ink |
P |
Pause |
Esc |
Quit to menu |
T / C / G / R |
Toggle textures / collision boxes / grid / raycasts |
F1 |
Show FPS |
Building From Source
The project uses CMake and C++20, with SFML 2 and Dear ImGui (via ImGui-SFML).
Windows (Visual Studio)
SFML is included as static libraries in dependencies/SFML, so no separate install is needed.
- Clone the repository
- Open the folder in Visual Studio (2022 or later), which detects
CMakePresets.json - Select the x64 Debug or x64 Release preset
- Build and run
Galatic_Inc_Alpha.exe
Linux
On Linux the project links against the system’s SFML, so install SFML 2.x first (for example sudo apt install libsfml-dev), then:
git clone https://github.com/NateTheGrappler/Galatic_Inc_Alpha.git
cd Galatic_Inc_Alpha
mkdir build && cd build
cmake ..
make
./Galatic_Inc_Alpha
Asset paths are compiled in relative to the source folder, so the game finds its textures and levels no matter where you run it from.
Project Structure
include/ engine headers: Game, Scene, Entity, components, physics, animation
src/ the game, the scenes and the level editor
assets/ hand-drawn textures, fonts and assets.txt (the asset manifest)
levels/ the built-in levels: Tutorial, Mercury → Neptune
createdLevels/ levels saved from the editor
dependencies/ SFML and Dear ImGui
Credits
- The engine architecture follows the patterns taught in Dave Churchill’s COMP 4300: Intro to C++ Game Programming lectures at Memorial University. Everything built on top of it, including the game, its systems, the level editor and all the art, is my own.
- SFML for windowing, graphics and input
- Dear ImGui and ImGui-SFML for the editor and debug UI
License
MIT. See LICENSE.txt.