Skip to content

giansimone/snake-game-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

C++ SDL3 License

A Snake Game in C++ (SDL3)

Example Screenshot

Overview

This is a simple snake game implemented in C++ using the SDL3 library. The game allows players to control a snake that grows longer as it eats food, with the objective of avoiding collisions with itself and the walls. The game features basic graphics, providing a nostalgic experience reminiscent of classic arcade games.

Features

  • Simple and intuitive controls.
  • Snake grows longer as it eats food.
  • Randomly generated food.
  • Game over condition when the snake collides with itself or the walls.
  • Score tracking.
  • Basic graphics using SDL3.

Requirements

  • C++ compiler (C++23 or later)
  • SDL3 library
  • CMake (for building the project)
  • Git (for cloning the repository)

Installation

  1. Clone the repository:

    git clone https://github.com/giansimone/snake-game-cpp.git
    cd snake-game-cpp
  2. Install SDL3:

    • On Ubuntu:
      sudo apt install libsdl3-dev
    • On macOS, you can use Homebrew:
      brew install sdl3
    • On Windows, follow the instructions on the SDL3 website to download and set up SDL3.
  3. Build the project using CMake:

    mkdir build
    cd build
    cmake ..
    make
  4. Run the game:

    ./bin/snake

Controls

  • Arrow keys to move the snake (Up, Down, Left, Right) or WASD keys.
  • Press Esc to exit the game.
  • Press R to restart the game after a game over or to reset the game.
  • Press P to pause and resume the game.

Gameplay

  • The snake starts with a length of 1 and grows by 1 unit each time it eats food.
  • The game ends when the snake collides with itself or the walls.

Contributing

Contributions are welcome! If you have suggestions for improvements or new features, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

A C++ implementation of the snake game based on SDL3.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published