Skip to content

jayphan14/CPP-Game-Engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ Game Engine

A small, header-light 2D game engine for terminals built on ncurses. It exposes a tiny set of building blocks — Characters, Movements, and Relationships that client code composes into a game. The included game is a Breakout-style demo (src/main.cc) that exercises every part of the engine.

Breakout demo

Quick start

make           # builds build/breakout
make run       # plays interactively
make snapshot  # prints a 25x80 text frame to stdout

Controls: w / a / s / d to move the paddle. Ctrl+C to quit.

Requires a C++20 compiler and ncurses. On macOS with Homebrew the Makefile auto-detects /opt/homebrew/opt/ncurses.

Layout

src/      engine + game source
build/    objects and the breakout binary (created by make)
docs/     README screenshot

Engine model

Concept Role
Engine Owns characters and relationships; ticks the world and renders a top-down view
Display Thin ncurses wrapper
Character Abstract entity with X/Y/Z, health, attack, and a list of movements
Movement Strategy applied each tick to mutate a character's position / visibility
Relationship Pairwise interaction between two characters (collision rule, etc.)

Concrete characters: SingleCharacter, RectangleCharacter, BitMapCharacter. Concrete movements: StraightLine, UserInputMovement, HideMovement, UnhideMovement. Concrete relationships: PassThrough, BounceOff, Battle.

The Z value is a draw-priority — higher Z wins overlap rendering, and characters at different Z values pass through each other.

Writing a game

src/main.cc is the example. The shape of any game is the same:

  1. initscr() / noecho() / nodelay(stdscr, true) to set up ncurses.
  2. Construct an Engine(width, height).
  3. Create characters, attach movements with addMovement.
  4. Wire up BounceOff / Battle / etc. relationships between pairs.
  5. Call engine.play().

Headless snapshot mode

./build/breakout --snapshot N runs N simulation ticks with no input and prints the resulting frame as plain text. The README screenshot above was rendered from such a snapshot.

References

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors