A terminal-based Space Invaders game built in Rust, demonstrating core game development concepts and Rust programming patterns.
This project implements a classic Space Invaders game that runs in the terminal. Players control a spaceship at the bottom of the screen, moving left and right to avoid enemy fire while shooting down descending invaders.
The game is developed through the course Udemy: Ultimate Rust Crash Course with extra improvements and code organization.
-
Controls:
←/→- Move left/rightSPACE/ENTER- ShootESC/q- Exit game
-
Objective: Defeat all invaders before they reach the bottom of the screen
- Frame-based update system using delta time (
Instant::elapsed()) - Continuous rendering and input polling
- Time-managed game state updates for smooth gameplay
Drawabletrait: Defines a common interface for all renderable game objects- Enables polymorphic rendering across different entity types
- Player, Invaders, and Shots all implement
Drawable
Tickabletrait: Standardizes time-based state updates for game entities- Provides consistent interface for delta-time updates
- Returns a boolean to indicate entity lifecycle (alive/dead)
- Game timing semantics: idiomatic Rust naming for time-stepped updates
- Clean separation of concerns through trait-based design patterns
Player: Manages player position, movement, and shotsInvaders: Manages enemy state, movement patterns, and wave managementFrame: 2D grid buffer for renderingDisplay: Handles terminal rendering and screen managementShot: Represents projectiles with collision tracking
- Non-blocking keyboard input using
crossterm::event - Command enumeration (
GameCommand) for clean action dispatch - Support for multiple input types (arrow keys, space, escape)
- Multi-threaded architecture: Separates game logic from rendering
- Message Passing: Uses
std::sync::mpscchannels for thread communication - Frame Buffering: Prevents tearing through double-buffering pattern
- Main thread handles game logic; dedicated thread manages display updates
- Integration with
rusty_audiolibrary - Sound effects for player actions (shooting, explosions, lose/win states)
- Non-blocking audio playback during gameplay
crosstermlibrary for cross-platform terminal API- Raw mode terminal input processing
- Cursor hiding and alternate screen buffer usage
- Clean terminal state management on exit
- Hit detection between player shots and invaders
- Boundary checking for player movement and invader progression
- Win/lose condition evaluation
- Structured game state with clear ownership models
- Mutable state updates following Rust's borrowing rules
- Event-driven architecture with command patterns
- Frame rate control using time intervals
- Consistent gameplay speed across different systems
- Time-based animation updates using
rusty_time
crossterm(v0.17.5): Terminal manipulation and raw input handlingrusty_audio(v1.1.4): Audio playback for sound effectsrusty_time(v0.11.0): Time utilities for game timing
The project includes comprehensive unit tests for core components:
- Shot Structure: 12 unit tests covering:
- Entity creation and initialization
- Time-based movement and position updates
- Collision and explosion states
- Rendering with different visual states
- Boundary conditions and edge cases
Run tests with:
cargo testThis project demonstrates:
- Rust ownership and borrowing principles
- Trait-based polymorphism and abstraction
- Multi-threaded programming with channels
- Game loop pattern and time-delta updates
- Clean architecture and separation of concerns
- Cross-platform terminal application development
- Enum-based state and command patterns
