A retro-style Snake game built with Rust and Macroquad, featuring a Matrix-inspired aesthetic with procedural map generation and dynamic gameplay.
- Classic Snake mechanics with smooth movement and collision detection
- Procedural map generation with configurable wall density
- Configurable game speed for different difficulty levels
- Score tracking with persistent best score storage
- Matrix-inspired aesthetic with green color palette
- Dynamic glyph rendering using Matrix-style characters (0, 1, <, >, [, ], etc.)
- Animated Matrix rain background for immersive atmosphere
- Responsive scaling that adapts to different screen sizes
- Fullscreen mode with high DPI support for immersive gameplay
- Adaptive UI with centered text and dynamic scaling for all screen resolutions
- Map preview in lobby with animated snake demo showing current difficulty settings
- Procedurally generated sound effects using WAV synthesis
- Eat sound (880Hz tone) when consuming food
- Death sound (110Hz tone) when game ends
- Adjustable volume with dedicated settings screen
- Persistent volume settings saved across game sessions
- Save system using JSON for game settings and high scores
- Persistent configuration of last used seed, wall density, and speed
- Best score tracking across game sessions
- Sound volume persistence with automatic restoration on launch
- Q - Quit the game (from any screen)
- Arrow Keys or WASD - Move the snake
- R - Restart game (when game over)
- Enter - Start new game (when "Start" is selected)
- ↑ / ↓ - Navigate menu items
- ← / → - Adjust selected setting (wall density or speed)
- R - Generate new random seed
- - / + - Decrease/Increase wall density (0-35%)
- [ / ] - Decrease/Increase game speed (50-350ms)
- S - Open settings screen
- ← / → or - / + - Adjust sound volume (0-100%)
- M - Toggle mute/unmute
- Enter or Esc - Return to lobby
- R - Restart game with same settings
- Enter - Return to lobby
- Q - Quit game
- State-based design with four main screens: Lobby, Settings, Playing, GameOver
- Modular components for map generation, snake logic, and rendering
- Efficient collision detection using HashSet for wall positions
- Deterministic map generation using seeded random number generation
- Dynamic screen management with smooth transitions between states
- Adaptive rendering using screen dimensions for multi-resolution support
- 60 FPS target with smooth frame timing
- Efficient rendering with glyph-based graphics
- Memory-efficient data structures for game state
- macroquad 0.4 - Cross-platform game framework
- serde - Serialization for save data
- serde_json - JSON format support
- Rust 1.70+ with Cargo
- OpenGL 3.3+ compatible graphics card
# Clone the repository
git clone <repository-url>
cd snake_macroquad
# Run the game
cargo run --release# Run in debug mode
cargo run
# Build for release
cargo build --release- Seed-based generation ensures reproducible maps
- Wall density controls difficulty (0-35% of cells)
- Safe spawn area prevents immediate collision
- Move interval controls snake speed (50-350ms)
- Grid size is fixed at 32x24 tiles
- Tile size scales with screen resolution
- Sound volume adjustable from 0-100% (persisted across sessions)
- Fullscreen mode enabled by default
- High DPI support for crisp rendering on high-resolution displays
- Adaptive scaling ensures proper display on any screen size
snake_macroquad/
├── src/
│ └── main.rs # Main game logic and rendering
├── img/
│ └── game_over.png # Screenshot for documentation
├── Cargo.toml # Project dependencies
├── Cargo.lock # Dependency lock file
├── snake_save.json # Persistent save data (auto-generated)
├── CHANGELOG.md # Project changelog
└── README.md # This file
const MATRIX_GLYPHS: &[u8] = b"01<>[]{}()/\\|-=+*;:.,^~ABCDEFGHIJKLMNOPQRSTUVWXYZ";
fn matrix_char_for_cell(c: Cell) -> char {
let hx = (c.x as i64).wrapping_mul(73_856_093);
let hy = (c.y as i64).wrapping_mul(19_349_663);
let h = (hx ^ hy).unsigned_abs() as usize;
MATRIX_GLYPHS[h % MATRIX_GLYPHS.len()] as char
}fn generate(seed: u64, wall_density: f32) -> Self {
macroquad::rand::srand(seed);
// Generate border walls and random interior walls
// Ensure safe spawn area around center
}fn generate_wav_sine(frequency_hz: f32, duration_seconds: f32, volume: f32) -> Vec<u8> {
// Generate WAV file data for simple sine wave tones
}Feel free to submit issues, feature requests, or pull requests to improve the game!
This project is open source. Feel free to use and modify as needed.
Built with ❤️ using Rust and Macroquad
