COsuDE Developer Documentation â
Overview â
COsuDE is a Rust-based typing game built with the Bevy game engine. Players type falling words to score points, with difficulty levels and penalties for mistakes. The game features a sci-fi aesthetic with neon colors and animations.
Architecture â
The project follows Bevy's ECS (Entity Component System) architecture. The main application is set up in main.rs, with game logic split across modules. States manage screen transitions, and systems handle updates.
Project Structure â
src/main.rs: Application entry point and setupsrc/components.rs: Entity components and resourcessrc/states.rs: Game state definitionssrc/config.rs: Constants and configurationsrc/words.rs: Word list for gameplaysrc/systems.rs: Utility systems (camera setup)src/ui.rs: UI spawning and managementsrc/menu.rs: Menu and difficulty selection logicsrc/game.rs: Core gameplay systems
Dependencies â
bevy = "0.13": Game engine providing ECS, rendering, input, etc.rand = "0.8": Random number generation for word shuffling
Key Components and Resources â
Components (components.rs) â
FallingWord: Represents a falling word with text, typed portion, and completion statusVelocity: Movement vector for falling entitiesFadeOut: Timer for fade-out animationsFlash: Temporary color flash effect with timerDifficultyButton: Marker for difficulty selection buttons- UI Components:
LoadingUI,MenuUI,StartButton,QuitButton,HighScoreText,DifficultyUI,PlayingUI,CurrentScoreText
Resources â
Score: Current and high score trackingSelectedDifficulty: Chosen difficulty levelClearColor: Background color
Enums â
Difficulty: Easy (5 words), Medium (10 words), Hard (all words)GameState: Loading, Menu, DifficultySelect, Playing, Score
Systems and Functions â
Core Systems (main.rs) â
setup_camera: Spawns 2D camera on startup- State transitions managed via
NextState<GameState>
UI Systems (ui.rs) â
spawn_loading_ui: Creates loading screen textdespawn_loading_ui: Removes loading UIspawn_menu_ui: Creates main menu with title, high score, start/quit buttonsdespawn_menu_ui: Removes menu UIspawn_difficulty_ui: Creates difficulty selection screendespawn_difficulty_ui: Removes difficulty UIspawn_playing_ui: Creates in-game score displaydespawn_playing_ui: Removes playing UI
Menu Systems (menu.rs) â
loading_system: Timer-based transition from loading to menumenu_button_system: Handles start/quit button interactions and state changesupdate_high_score_text: Updates high score displayupdate_current_score_text: Updates current score during gameplaydifficulty_select_system: Handles difficulty button interactions
Gameplay Systems (game.rs) â
spawn_words: Creates falling word entities based on selected difficultyfalling_system: Updates word positions downwardtyping_system: Processes keyboard input, updates typed text, handles penalties/completionsupdate_text_system: Updates word text rendering with colors and flash effectsfade_system: Handles fade-out animations for completed wordswin_condition_system: Checks for game completion and resets
Gameplay Flow â
- Loading: 2-second loading screen
- Menu: Display high score, start/quit options
- Difficulty Select: Choose Easy/Medium/Hard
- Playing: Type falling words, avoid penalties, complete all words to win
- Win: Return to menu with updated high score
UI Interactions â
- Buttons use
Interactionqueries for hover/press states - Colors change on interaction (neon blue hover, purple press)
- Text colors: Neon blue (#00d4ff) for titles/scores, white for buttons
- Panels: Semi-transparent black (#00000080) with neon borders
Word Rendering â
- Typed portions: Neon blue (#00d4ff)
- Untyped portions: Dim gray (#808080)
- Flash effects: Red-orange (#ff6b6b) for penalties, green for completions
- Font size: 50px for words, 45-70px for UI text
Scoring â
- Correct word completion: 10 points à word length
- Backspace penalty: -2 points
- Invalid input reset: -5 points
- Negative scores allowed, instant fail if score < 0
Configuration (config.rs) â
WINDOW_WIDTH: 800.0WINDOW_HEIGHT: 600.0FONT_SIZE: 50.0 (word size)FALL_SPEED: 100.0 (pixels/second)FADE_DURATION: 1.0 (seconds)
Word List (words.rs) â
Contains 73 Rust/programming-related words for typing practice.
State Management â
Uses Bevy's States for screen management. Transitions triggered by user input or timers.
Rendering â
- 2D camera with default bundle
- Text2dBundle for falling words
- NodeBundle for UI panels
- ButtonBundle for interactive elements
Input Handling â
ReceivedCharacter: For typed lettersKeyboardInput: For backspace detection- Input processed in
typing_systemwith character validation
Animations â
- Falling: Continuous downward movement
- Fade-out: Alpha reduction over time
- Flash: Temporary color override with timer
- No particle effects or complex animations implemented
Error Handling â
- Word reset on invalid input
- Score penalties for mistakes
- Entity existence checks before despawning (prevents B0003 warnings)
Performance Considerations â
- Words shuffled once per game start
- Systems run conditionally based on state
- Entities despawned after use
Extensibility â
- Easy to add new difficulties or word lists
- UI screens modular and reusable
- Systems separated by concern (UI, menu, gameplay)
Build and Run â
cargo run: Build and run the gamecargo check: Verify compilation- Requires Rust 2024 edition
This documentation provides a complete overview of COsuDE's codebase, interactions, and functionality for developers.