Skip to content

gtRZync/snake-game-winapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake Game in C (Windows API)

License: MIT Made with C WinAPI Windows Only Repo Size Last Commit Top Language

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.


Features

  • 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

Node Cleanup + Logging

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.

Tech Stack

  • Language: C (C99)

  • Graphics: Win32 GDI with sprite blitting

  • Platform: Windows (Desktop)

  • Compiler: gcc.exe or any Win32-compatible C compiler


Limitations (for now)

  • No sound effect

How to Play

  1. 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
  1. Open the Project in VS Code Navigate to the project folder and open it using your preferred code editor (VS Code recommended).

  2. 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.


Controls

  • Arrow Keys — Move the snake
  • ESC — Exit the game

Gameplay

Snake Game


Coming Soon

  • More sprite-based graphics
  • Sound effects?

License

This project is licensed under the MIT License.

Releases

No releases published

Packages

No packages published