Fork me on GitHub

Project Notes

#361 Snake

Build and update the snake game example from Rust lang: The complete beginner’s guide, learning about making GUI games with Piston and Rust.

Notes

This project is adapted from an example given in the Rust lang: The complete beginner’s guide course. Dependencies and code have been updated to work cleanly in 2025.

Project Structure

Main

See snake/src/main.rs

Creates the game window and handles hte main event loop.

Game

See snake/src/game.rs

Implements game logic.

Snake

See snake/src/snake.rs

Manages position. movement and growth of the snake. Snake segments managed in a linked list.

Draw

See snake/src/draw.rs

Some higher-level drawing functions that translate from game to window coordinates.

Running the Game

How the game works:

  • arrow keys to change snake direction left or right, else it moves straight ahead
  • snake dies if it hits the edge of the box
  • snake dies if it runs over its own tail
  • snake grows by 1 unit when it eats an apple
  • a new apple appears at a random position on the screen when one is eaten
  • when game is over, it restarts automatically after 1s
$ cargo run
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.17s
    Running `target/debug/snake`

On startup:

snake

Game over!

game over

Improvements?

Obviously, it’s just a basic game structure at this point. Some features that could be added:

  • scoreboard
  • sound

Credits and References

About LCK#361 rust

This page is a web-friendly rendering of my project notes shared in the LittleCodingKata GitHub repository.

Project Source on GitHub Return to the LittleCodingKata Catalog
About LittleCodingKata

LittleCodingKata is my collection of programming exercises, research and code toys broadly spanning things that relate to programming and software development (languages, frameworks and tools).

These range from the trivial to the complex and serious. Many are inspired by existing work and I'll note credits and references where applicable. The focus is quite scattered, as I variously work on things new and important in the moment, or go back to revisit things from the past.

This is primarily a personal collection for my own edification and learning, but anyone who stumbles by is welcome to borrow, steal or reference the work here. And if you spot errors or issues I'd really appreciate some feedback - create an issue, send me an email or even send a pull-request.

Follow the Blog follow projects and notes as they are published in your favourite feed reader