A classic Snake game implementation written entirely in C using the Raylib graphics library. The game features smooth gameplay, collision detection, pause functionality, and increasing difficulty as you progress.
Warning
This game was developed in the Linux operating System, compatibility with the windows sytem is not suported :/
Note
More info about the web assembly build read the web_build.md and looking on the web build branch.
- Classic Snake Gameplay: Control the snake to eat food and grow longer
- Collision Detection: Snake wraps around screen edges and detects self-collision
- Progressive Difficulty: Game speed increases as you eat more food
- Pause System: Pause and resume the game with an interactive menu
- Clean Graphics: Simple, clean visual design with grid-based movement
Before building and running the game, ensure you have the following installed:
- CMake (version 3.22 or higher)
- Clang compiler
- Make build tool
- Git (for fetching dependencies)
On Ubuntu/Debian systems, you'll also need these libraries:
sudo apt update
sudo apt install build-essential cmake clang git
sudo apt install libx11-dev libxrandr-dev libxinerama-dev libxcursor-dev libxi-devThe project includes a convenient shell script that handles building and running the game.
To build and run the game in one command:
./script.shThe script.sh script supports several options:
./script.sh --build./script.sh --runBuild and run with debug symbols:
./script.sh --debugBuild only in debug mode:
./script.sh --debug --buildIf you prefer to build manually using CMake:
# Configure the project
cmake -D CMAKE_C_COMPILER=clang . -B ./build
# Build the project
make -C ./build
# Run the game
./build/snake_gameFor debug builds:
cmake -D CMAKE_C_COMPILER=clang -D CMAKE_BUILD_TYPE=Debug . -B ./build
make -C ./build
./build/snake_game- Arrow Keys or WASD: Control snake direction
W/↑: Move UpA/←: Move LeftS/↓: Move DownD/→: Move Right
- Space: Pause/Resume the game
- Enter: Select option in pause menu (when paused)
- ↑/↓: Navigate pause menu options
├── src/
│ ├── main.c # Main game loop and initialization
│ ├── game.c/.h # Core game logic and state management
│ ├── snake.c/.h # Snake entity and behavior
│ ├── food.c/.h # Food entity and generation
│ ├── map.c/.h # Game map and tile system
│ ├── gui/
│ │ └── pause.c/.h # Pause menu implementation
│ └── array-list/
│ └── d_array_list.c # Dynamic array implementation
├── CMakeLists.txt # CMake build configuration
├── script.sh # Build and run script
├── .clangd # Language server configuration
├── .gitignore # Git ignore rules
└── license.md # MIT License
The project automatically fetches and builds Raylib as a dependency through CMake's FetchContent module. No manual dependency installation is required.
This project is licensed under the MIT License. See license.md for details.
If you encounter build issues:
- Ensure all prerequisites are installed
- Try cleaning the build directory:
rm -rf build/ - Run the build command again:
./script.sh --build
- Black screen: Ensure your system supports OpenGL
- Input not working: Try running in a different terminal or environment
- Performance issues: The game is designed to run at 60 FPS; check system resources
Feel free to fork this project and submit pull requests for improvements, bug fixes, or new features!
