0
NateTheGrappler/ Galatic_Inc_Alpha
A custom 2D game engine built from scratch in C++ and SFML
  • NateTheGrappler
NateTheGrappler
Galactic Inc
November 22, 2024|Github|Content
  • C++
  • SFML
  • Game Engine
  • ECS
  • Level Editor
  • Game Art
  • Game Dev

Galactic Ink

A 2D platformer and the custom C++ game engine it runs on, built with SFML on an entity-component-system architecture.

Devlog 1 · Devlog 2

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

Galactic Ink

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:

  1. Input: read input and update the player’s CInput
  2. GUI: the debug window
  3. Movement: apply input, gravity and velocity; pushing, carrying and throwing boxes
  4. Animation: advance every entity’s animation and pick the right one for its current state
  5. Lifespan: destroy entities whose time is up
  6. Raycasting: update enemy line of sight
  7. Render: draw the frame
  8. 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.

Galactic Ink

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.

  1. Clone the repository
  2. Open the folder in Visual Studio (2022 or later), which detects CMakePresets.json
  3. Select the x64 Debug or x64 Release preset
  4. 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

License

MIT. See LICENSE.txt.