A classic Snake game built in pure C using only the Windows API — no external libraries, no dependencies. Retro-style visuals and (semi)smooth gameplay, all rendered with custom sprites and Win32 code.
- Classic Snake gameplay
- Pure Win32 API (no SDL, no OpenGL, no dependencies)
- Snake and pellet rendered using GDI objects and custom functions
- Animated Sprite pellet
- Snake body handled with a linked list
- Collision detection with pellets
- Node-freeing system with logging (see below)
- restart Game
When the game quits (or when restart is added later), each segment of the snake is freed from memory, and a log is created:
- The log shows the timestamp and number of freed nodes
- If the log file can’t be opened, cleanup still happens — no leak, just no log
Example log.txt
entry:
Log date and time : [Mon Apr 07 10:45:15 2025]
freeing node with coord (5, 17) (node: 1)
freeing node with coord (5, 16) (node: 2)
freeing node with coord (5, 15) (node: 3)
freeing node with coord (5, 14) (node: 4)
freeing node with coord (5, 13) (node: 5)
freeing node with coord (5, 12) (node: 6)
freeing node with coord (5, 11) (node: 7)
freeing node with coord (5, 10) (node: 8)
log :
8 nodes were freed.
-
Language: C (C99)
-
Graphics: Win32 GDI with sprite blitting
-
Platform: Windows (Desktop)
-
Compiler: gcc.exe or any Win32-compatible C compiler
- No sound effect
- Clone the Repository
Download the game by cloning the repo or grabbing the ZIP file:
git clone https://github.com/gtRZync/snake-game-winapi.git
-
Open the Project in VS Code Navigate to the project folder and open it using your preferred code editor (VS Code recommended).
-
Build and Run the Game Open the terminal inside your IDE and run:
make run
This will compile the game using the Makefile
and launch it automatically.
- Arrow Keys — Move the snake
- ESC — Exit the game
- More sprite-based graphics
- Sound effects?
This project is licensed under the MIT License.