Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Latest commit

 

History

History
25 lines (17 loc) · 1.6 KB

README.md

File metadata and controls

25 lines (17 loc) · 1.6 KB

ARCHIVED: Merged as part of SDL3 examples, you can see it at https://github.com/libsdl-org/SDL/tree/main/examples/game/01-snake and you can play at https://examples.libsdl.org/SDL3/game/01-snake/ Snake gameplay

Snake game written in ANSI C

Everyone knows what the snake game is: You eat food, the line/snake grows bigger. There is not much else to it, you can read the Wikipedia article if you want more information. In particular, this version of Snake has the "snake", warping and multiple food.

I usually use this project as "testing grounds" for a new platform or development environment since its easily portable and I know its behavior very well, so if something goes very wrong its immediately noticeable.

Building

An ANSI C / C89 compliant compiler is needed, a C++ compiler works as well since this code is written with the -Wc++-compat compiler flag in mind, the only dependencies for this project are libc and SDL.

To compile you can simply do cc -I/usr/include/SDL2 -lSDL2 src/snake.c src/main.c on most systems. For more ellaborated building or development, you should use Meson.

Support to build with emscripten is provided! Assuming you have the toolchain in PATH already you can get started with:

meson setup --cross-file wasm-cross.ini build-emscripten && cd build-emscripten
meson compile
# Remember that you need a server to deliver the .wasm / .js files!
python -m http.server