A polished, modern take on the classic Snake game, built with C++ and the SFML multimedia library. Featuring multiple difficulty levels, dynamic obstacles, bonus food, and robust, modular game logic.
This project is a clean, expandable implementation of Snake, ideal for both players and developers looking to learn or extend a C++/SFML game. All core mechanics are encapsulated in a SnakeGame class, making the codebase easy to understand and maintain.
Food spawning is carefully handled so that new food never appears on the snake, obstacles, or UI elements, ensuring frustration-free gameplay.
- Multiple Difficulty Levels: Choose from Easy, Medium, or Hard
- Dynamic Obstacles: Obstacle number and placement scale with difficulty
- Bonus Food: Special timed food items for extra points
- Smart Spawning Logic: Food and bonuses never spawn in invalid locations
- Clean UI: Score panel at the top of the screen
- Arrow Keys: Move the snake
- ESC: Pause or exit
Goal: Eat as much food as possible to grow your snake and increase your score. Avoid colliding with walls, obstacles, or your own tail.
- C++17 compatible compiler (e.g., MinGW GCC)
- CMake (3.10+)
- CLion or your favorite C++ IDE
- SFML Library
-
Clone the repository
git clone https://github.com/loopholend/snake.git
-
Install SFML
- Download the version matching your compiler (e.g. GCC for MinGW-w64, 64-bit) from SFML Downloads
- Extract it to a stable location (e.g.
C:/dev/SFML-2.6.2)
-
Configure CMake
- Open the project in your IDE.
- Edit
CMakeLists.txt: Update theset(SFML_DIR ...)line to your SFML installation path.
set(SFML_DIR "C:/dev/SFML-2.6.2/lib/cmake/SFML")
- Ensure the following lines appear:
find_package(SFML 2.6 COMPONENTS graphics window system REQUIRED) target_link_libraries(snake PRIVATE sfml-graphics sfml-window sfml-system)
-
Copy SFML DLLs (Windows only)
- Copy all
.dllfiles fromC:/dev/SFML-2.6.2/binto your project's build output folder (typicallycmake-build-debug/)
- Copy all
-
Build and Run
- Reload the CMake project in your IDE
- Build and run – the game should launch!
- 0xc000007b Error: 32/64-bit mismatch. Ensure both compiler and SFML are 64-bit.
- Missing DLLs: Copy all SFML
.dllfiles to your build output folder. - CMake can't find SFML: Make sure
SFML_DIRinCMakeLists.txtis correct and points to the folder containingSFMLConfig.cmake.
This project is licensed under the MIT License. See LICENSE.txt for details.
- Built using the amazing SFML library