Skip to content

About

A classic Snake game written in Rust using SDL2

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

Snake Game — Rust + SDL2

A classic Snake game written in Rust using SDL2.

This project was created primarily as a learning exercise while exploring Rust, SDL2, game development, asset management, and related concepts. As a result, the code is not particularly clean or idiomatic in places—but it was a fun project to build and experiment with.

Features

  • Classic Snake gameplay
  • Keyboard-controlled movement
  • Menu navigation
  • Sound effects and music
  • Custom graphics and fonts
  • Packed game assets
  • Screenshot support

How to play

Controls

Key Action
Arrow Keys Navigate menus and control the snake
Enter / Return Select menu options
Ctrl + Print Screen Save a screenshot

Screenshots

Screenshot 1 Screenshot 2
Screenshot 3 Screenshot 4
Screenshot 5

Dependencies

  • rand;
  • sdl2, with the ttf, image and mixer features.

Make sure the required SDL2 development libraries are installed on your system before building the project.

Building and Running

Clone the repository and build the project with Cargo:

git clone https://github.com/delarco/snake-rust.git
cd snake-rust
cargo run --release

Alternatively, build without running:

cargo build --release

The resulting executable will be available in:

target/release/

Note: SDL2 must be installed and available on your system for the game to build and run.

Asset Management

Game assets are stored in a packed data.pck file.

The tools directory contains Python scripts for extracting and creating this asset pack.

Extract assets

To extract the contents of data.pck, run:

cd tools
python datapack_extract.py

The script extracts all assets from data.pck into:

tools/assets/

After extraction, the image, audio and font files can be edited directly.

Pack assets

To add a new asset:

  1. Add it's file index and name to tools/files.json.
  2. Copy the asset into tools/assets/.
  3. Update the AssetsEnum in src/assets.rs.
  4. Add the corresponding asset to the code where required.

To create a new data.pck file, run:

cd tools
python datapack_create.py

This creates a new data.pck containing all files mapped in tools/files.json.

All referenced files must exist in:

tools/assets/

Project Status

This is primarily a learning project rather than a polished or production-ready game.

The code contains areas that could be refactored, simplified, or made more idiomatic as my Rust knowledge improves.

TODO

  • Compress assets in the data pack
  • Implement a scoreboard
  • Add tests
  • Refactor and clean up the code

License

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

About

A classic Snake game written in Rust using SDL2

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages