A simple Snake game implemented in C using the Raylib library.
- Raylib - C game development library
- C Compiler (GCC, MinGW, Visual Studio, etc.)
- Windows/Linux/macOS
Windows (MinGW):
# Download from: https://www.raylib.com/
# Or use vcpkg:
vcpkg install raylibLinux (Ubuntu/Debian):
sudo apt install libraylib-devmacOS:
brew install raylibWindows (MinGW):
gcc main.c -o snake.exe -lraylib -lopengl32 -lgdi32 -lwinmmLinux:
gcc main.c -o snake -lraylib -lGL -lm -lpthread -ldl -lrt -lX11macOS:
gcc main.c -o snake -lraylib-
Run the game:
./snake.exe # Windows ./snake # Linux/macOS
-
Controls:
- โฌ๏ธ Up Arrow - Move up
- โฌ๏ธ Down Arrow - Move down
- โฌ ๏ธ Left Arrow - Move left
- โก๏ธ Right Arrow - Move right
- Enter - Restart after Game Over
-
Objective:
- Eat the red food to grow
- Avoid hitting the walls and yourself
- Get the highest score!
snake/
โโโ main.c # Main source code
โโโ README.md # This file
โโโ .gitignore # Files ignored by Git
- Only 80 lines of code - Minimalist implementation
- No external dependencies - Only Raylib
- Static memory - No malloc/free
- Efficient collision detection
- Responsive controls
Error: "raylib.h not found"
- Make sure you have Raylib installed correctly
- Verify that include paths are configured
Linking error:
- Check that you have all necessary libraries
- On Windows, make sure you have Raylib DLLs
Game runs slowly:
- The game is limited to 60 FPS
- Speed can be adjusted by modifying
frameCount >= 12in the code
This project is open source and available under the MIT License.
Improvements and suggestions are welcome! Feel free to fork and submit pull requests.