A simple implementation of the snake game in C, which works on Windows and Linux*.
Long overdue for me, it feels like writing an implementation of Snake is something everyone who's into C should ever try to do, so here's mine.
While there is no shortage of examples for how to write Snake in C on the internet, I just wanted to share my take on it, properly commented and whatnot.
My objectives for it:
- Code must be no more than 512 lines
- Game must weight no more than 32 kb
- Must use no more than 1 Mb of RAM during runtime (not counting the terminal application's memory usage).
- Have good movement. Snake C implementations will sometimes have a delay on inputs, or miss inputs in quick sucession.
- Work on both Windows and Linux (Failure explained below)
Usage: Control with WASD. Exit with 'o'.
Builds and works perfectly.
Build with gcc: gcc -pthread -s snake.c -O1 -o snepk.exe
Builds, and ALMOST works. Namely there is an issue with the terminal update rate that I cannot figure out. The terminal will only update while a key is being held down which makes the game barely playable.
Build linux: gcc -pthread -s snake.c -O1 -o snepk