Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake Game

A classic Snake game built with Rust and Bevy, a powerful data-driven game engine.

Project Overview

This is a modern implementation of the classic Snake game featuring:

  • A grid-based board system
  • Snake movement and collision detection
  • Food spawning and consumption mechanics
  • Score tracking
  • Customizable game title via environment variables
  • ECS (Entity Component System) architecture using Bevy

Technology Stack

  • Language: Rust
  • Game Engine: Bevy 0.15.3
  • Other Dependencies:
    • dotenvy - Environment variable management
    • rand - Random number generation for food placement

Project Structure

snake_game/
├── src/
│   ├── main.rs                 # Application entry point
│   ├── core/                   # Core game logic and data
│   │   ├── components.rs       # Bevy components (game entities)
│   │   ├── constants.rs        # Game constants
│   │   ├── events.rs           # Game events
│   │   ├── resources.rs        # Bevy resources (global state)
│   │   └── mod.rs
│   └── plugins/                # Bevy plugins (feature modules)
│       ├── board/              # Board/grid system
│       ├── camera/             # Camera control
│       ├── controls/           # Player input handling
│       ├── food/               # Food mechanics
│       ├── game/               # Game state management
│       ├── score/              # Score tracking
│       ├── shared/             # Shared systems
│       ├── snake/              # Snake mechanics
│       │   ├── helpers.rs      # Snake helper functions
│       │   └── mod.rs
│       └── mod.rs
├── assets/
│   └── fonts/                  # Game fonts
├── Cargo.toml                  # Rust project manifest
└── README.md                   # This file

Getting Started

Prerequisites

  • Rust (latest stable version recommended)
  • Cargo (comes with Rust)

Installation & Running

  1. Clone or extract the project:

    cd snake_game
  2. Run the game:

    cargo run
  3. To run with custom game title, create a .env file:

    GAME_TITLE=My Custom Snake Game

Building

Create an optimized release build:

cargo build --release

The compiled binary will be in target/release/.

Game Features

Controls

  • Arrow Keys or WASD - Move the snake
  • ESC - Exit game (or close window)

Gameplay

  • Guide your snake to eat food pellets
  • Avoid colliding with walls and yourself
  • Your score increases with each food consumed
  • Game ends on collision

Architecture

This project uses the Entity Component System (ECS) pattern provided by Bevy:

  • Components - Data attached to entities (e.g., snake position, direction)
  • Systems - Logic that operates on components
  • Resources - Shared global state (e.g., score, game state)
  • Plugins - Organized modules bundling related systems and components

Each feature (snake, food, board, etc.) is implemented as a separate plugin for modularity and maintainability.

Configuration

Game settings can be customized via environment variables (using .env file):

  • GAME_TITLE - Window title (default: "My Snake Game")

Check core/constants.rs for additional game constants like board size, grid cell size, etc.

Development

Code Organization

  • core/ - Pure game logic and data structures

    • Independent of rendering or input
    • Contains the game's business rules
  • plugins/ - Bevy-specific implementations

    • Each plugin handles a specific game feature
    • Contains systems that process components and resources

Building for Development

# Debug build (faster compilation, slower runtime)
cargo build

# Run with logging
RUST_LOG=debug cargo run

Common Tasks

  • Check code: cargo check
  • Run tests: cargo test
  • Format code: cargo fmt
  • Lint: cargo clippy

Future Enhancements

Potential features for expansion:

  • Difficulty levels
  • High score persistence
  • Power-ups and obstacles
  • Multiplayer support
  • Sound effects and music
  • Menu system
  • Different game modes

License

This project is open source. Feel free to use and modify as needed.

Resources


Enjoy the game! 🐍

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages