Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ Rust Snake Game

A classic Snake game written in Rust using the Piston Window library. The game offers smooth gameplay with animated visual effects and charming details.

Screenshot of the game

โœจ Features

  • Core Gameplay

    • Classic snake mechanics with growth system
    • Collision detection (walls and self)
    • Score tracking
  • Visual Enhancements

    • Directional snake eyes ๐Ÿ‘€
    • Animated flickering tongue ๐Ÿ‘…
    • Pulsating food effect ๐Ÿ’ซ
    • Multi-layered borders
  • Technical Features

    • VSync-enabled smooth rendering
    • Responsive controls
    • Automatic game restart

๐ŸŽฎ Controls

Key Action
Arrow Keys Change snake direction
Space Restart game
ESC Exit game

๐Ÿ› ๏ธ Requirements

  • Rust
  • Cargo

๐Ÿ“ฆ Installation and Running

  1. Clone the repository:
git clone https://github.com/Xeyo-Developer/Rust-SnakeGame/
cd Rust-SnakeGame
  1. Run the game:
cargo run

๐ŸŽฏ Game Rules

  1. Goal: Collect food (golden squares) to grow the snake
  2. Game Over: Hit the wall or your own tail
  3. Restart: Game automatically restarts after 1 second from game over
  4. Movement: Snake moves automatically, you only control the direction

๐Ÿ—๏ธ Architecture

The project consists of five main modules:

main.rs

  • Application entry point
  • Game window configuration (27x22 blocks)
  • Main game loop handling events and rendering

game.rs

  • Game logic and state management
  • Collision handling and win/lose condition checking
  • Food generation in random positions
  • Snake movement timer (200ms per move)

snake.rs

  • Snake implementation as a linked list of blocks
  • Movement and direction handling
  • Tongue animation with random timing
  • Self-collision detection

drawing.rs

  • All graphics rendering functions
  • Game coordinates to pixel conversion
  • Drawing blocks, eyes, tongue, and borders
  • Visual effects (gradients, shadows)

๐ŸŽจ Visual Details

  • Block size: 25x25 pixels
  • Board: 27x22 blocks (675x550 pixels)
  • Colors:
    • Background: Dark blue [0.08, 0.10, 0.12, 1.0]
    • Snake head: Dark green [0.20, 0.70, 0.20, 1.0]
    • Snake body: Light green [0.30, 0.80, 0.30, 1.0]
    • Food: Golden [0.96, 0.71, 0.20, 1.0]
  • Effects:
    • Block shadows for depth
    • Pulsating food
    • Animated tongue (red)
    • White eyes with black pupils

๐Ÿ”ง Dependencies

[dependencies]
piston_window = "0.146.0"
rand = "0.9"

๐Ÿ“„ License

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

About

๐Ÿ A snake game written in Rust.

Topics

Resources

Stars

Watchers

Forks

Releases

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.