How chezyname/survive works
1. Overall shape
- This is a native Rust, single-player top-down survival game with a strong “game loop + state machine” architecture.
- The code is organized into gameplay systems, menu/UI systems, and a reusable item/power-up system, with assets stored locally under assets/.
2. Application entry and runtime
- src/main.rs is the entry point that wires the game together and starts the runtime.
- The project is built and run with standard Cargo tooling; there are no external backend services or network dependencies in the repository.
3. Core state management
- src/gamestate.rs appears to be the central boundary for switching between high-level modes such as main menu, gameplay, shop, and game over.
- The menu-related files (main_menu.rs, menu_base.rs, shop.rs, game_over.rs) are likely separate state implementations that plug into the shared game-state flow.
4. Gameplay loop
- The core survival loop is split across player.rs, enemy.rs, projectile.rs, wave.rs, and wave_manager.rs.
- The likely data flow is: waves are generated/spawned by the wave manager, enemies are updated, the player attacks via projectiles, and combat outcomes feed back into player health, gold, and progression.
5. Player model and stats
- player.rs and player_stats.rs separate runtime player behavior from stat bookkeeping.
- This suggests a boundary between transient gameplay state (position, health, attacks) and upgradeable attributes (damage, crit, speed, etc.), which is important for diagramming how items modify the player.
6. Item / card subsystem
- src/items/ is a major subsystem: each file is a distinct upgrade/card type such as damage, crit, lifeline, shotgun, rapid fire, explosion, gold multipliers, and wave-related effects.
- The README shows items implement a shared Item trait and are registered through an ItemFactory, so the item system is effectively a plugin-like registry of purchasable upgrades.
7. Shop and progression flow
- src/shop.rs is the likely point where item choice, cost, and purchase conditions are evaluated.
- Items can be unique, conditional, or repeatable, which means the shop depends on current player state to determine availability and shapes the progression loop between combat rounds.
8. UI and presentation
- src/player_ui.rs handles in-game HUD elements such as health, resources, and possibly current build/status.
- src/config.rs likely holds shared formatting and display helpers used by UI and descriptions, keeping presentation logic separate from gameplay rules.
9. Audio subsystem
- src/audio.rs is the central interface for sound/music playback.
- The assets/audio/*.ogg files show clearly separated effects and music for menu, gameplay, shop, hurt, explosion, selection, and game-over states, so audio is state-driven and event-driven rather than ambient.
10. Assets and content packaging
- assets/ contains runtime content rather than code, including audio and fonts.
- That means the executable depends on local asset loading at runtime, and the visual/audio identity of the game is bundled with the binary rather than fetched externally.
11. Supporting utilities
- LineReader.py is present as a standalone helper script, but it is not part of the Rust runtime architecture shown by the main source tree.
- CREDITS.md, LICENSE, and README.md are documentation/support files rather than runtime systems.
12. Architectural summary
- The main architectural boundary is between state management (menu/shop/gameplay/game-over), combat simulation (player/enemy/projectile/waves), and progression (items/shop/player stats), with audio/UI layered around those systems.
- For a diagram, the most important flow is: startup → menu → gameplay loop → wave/combat updates → rewards/shop/item upgrades → eventual game over → return to menu.
Main entry points: player.rs Player · audio.rs Audio · gamestate.rs Game State · shop.rs Shop
Components 18
Runtime
Entry, state flow, and the main play loop.
- Main · Starts the game and wires the runtime.
src/main.rs - Game State · Central boundary for switching between menu, gameplay, shop, and game over.
src/gamestate.rs - Menu Base · Shared menu/state behavior used by menu screens.
src/menu_base.rs - Main Menu · Front-door state before gameplay begins.
src/main_menu.rs - Shop · Handles item selection, cost, and purchases.
src/shop.rs - Game Over · Terminal state shown after defeat.
src/game_over.rs
Systems
Gameplay, combat, progression, UI, and audio subsystems.
- Wave Manager · Drives wave generation and pacing.
src/wave_manager.rs - Wave · Defines wave composition and progression rules.
src/wave.rs - Player · Runtime player behavior, movement, combat, and health.
src/player.rs - Player Stats · Upgradeable player attributes and persistent combat modifiers.
src/player_stats.rs - Enemy · Enemy behavior, targeting, and combat interactions.
src/enemy.rs - Projectile · Fired attacks and hit resolution.
src/projectile.rs - Player UI · In-game HUD for health, resources, and status.
src/player_ui.rs - Audio · Central playback interface for music and sound effects.
src/audio.rs - Config · Shared formatting and presentation helpers.
src/config.rs
Connections 24
- Main → Game State: boot · Initializes the game and hands control to state management.
- Game State → Main Menu: menu · Routes into the main menu state.
- Game State → Shop: shop · Switches to the shop/progression state.
- Game State → Game Over: lose · Transitions to the game over state.
- Main Menu → Menu Base: uses · Builds on shared menu behavior.
- Game State → Player: play · Enters the gameplay loop.
- Player → Player Stats: stats · Reads and updates player attributes.
- Player → Projectile: fires · Creates attacks during combat.
- Player → Enemy: hits · Deals damage in combat.
- Wave Manager → Wave: spawns · Generates and schedules enemy waves.
- Wave → Enemy: contains · Defines enemy encounters within a wave.
- Enemy → Player: targets · Threatens the player during survival play.
- Projectile → Enemy: damages · Applies combat outcomes to enemies.
- Shop → Items: purchases · Uses the item registry to present upgrades.
- Items → Item Types: loads · Registers concrete upgrade implementations.
- Shop → Player Stats: upgrades · Changes player capabilities through purchases.
- Player UI → Player: displays · Renders player state in the HUD.
- Player UI → Config: formats · Uses shared presentation helpers.
- Audio → Assets: loads · Plays bundled audio content from disk.
- Main Menu → Audio: music · Triggers menu music and selection effects.
- Shop → Audio: sfx · Plays shop and selection sounds.
- Game Over → Audio: music · Triggers game-over audio.
- Player → Audio: sfx · Uses gameplay audio cues such as hurt and attacks.
- Wave Manager → Audio: sfx · Drives encounter sound cues.