This repository contains a small C project that shows how basic data structures are used in simple 2D games. The focus is not on fancy graphics, but on how arrays, structs, and simple state management can be combined to build playable games.
The main example is the Arcade Game Collection, which currently includes two games:
Dino RunFlappy Bird
Everything is written in C and organized so you can see where and how each piece of game state is stored and updated.
Data-Structures-and-Algorithms/
├── README.md
└── Arcade Game Collection/
├── main.c // menu / game launcher
├── common.h
├── common.c // shared helpers and data
├── dino_run.h
├── dino_run.c // Dino Run implementation
├── flappy_bird.h
├── flappy_bird.c // Flappy Bird implementation
- Uses C
structs to represent reusable concepts (for example, a generic game object or configuration). - Centralizes shared data that is used by both games (for example, screen dimensions, input handling helpers, or random number utilities).
- Arrays of obstacles: Stores the active obstacles in an array so the game loop can iterate over them each frame, move them, and check for collisions with the player.
- Player state struct: Groups together the dino's position, velocity, jump state, and other attributes into a single
structso it can be passed around and updated cleanly. - Game state variables: Tracks whether the game is running, paused, or over using a small set of state variables (a simple state machine).
- Score tracking: Keeps the current score and possibly high score in basic numeric variables that are updated when the player survives longer or passes obstacles.
- Arrays of pipes: Stores pipe positions and gaps in an array so each frame can update positions and detect when the bird collides or successfully passes through a gap.
- Bird state struct: Similar to Dino Run, groups the bird's position, velocity, and alive/dead state into a
struct. - Game loop state: Maintains a simple state machine (ready, playing, game over) using variables or enums to control which logic to run.
- Shared helpers: Reuses functions from
common.cto avoid duplicating utility logic between games.
Overall, the project shows how even small games naturally organize their data into arrays, structs, and simple state machines so the main game loop can iterate, update, and render consistently.
This project is designed to be built with make from within the Arcade Game Collection folder.
From the root of the repository:
cd "Arcade Game Collection"
makeThis should produce a single executable (commonly named something like arcade or main, depending on your Makefile).
To run the compiled game collection:
./arcade # or ./main, depending on the MakefileIf your Makefile has a specific target for running everything at once, you can also use:
make runTo remove the compiled executable and object files after building, run:
cd "Arcade Game Collection"
make cleanThis will delete temporary build outputs so you can rebuild from a clean state.
- How to represent game entities (player, obstacles, pipes) with C
structs. - How to store multiple entities in arrays and loop over them each frame.
- How to keep game state (scores, modes, flags) in a small set of well-defined variables.
- How to organize a small C project into multiple
.c/.hfiles.