How holymonkey/asteroids works
Project Type and Purpose
• This is a Unity game project – a clone of the Asteroids game.
• Its purpose is to demonstrate how game logic can be separated into a model independent of Unity’s typical MonoBehaviour framework.
• The README indicates that it’s a vanilla Unity project (without dependency injection frameworks like Zenject) and serves as a base for students to refactor problematic design aspects.
Analysis of the File Structure
• Top-Level Organization:
• There are typical Unity directories (Assets, Packages, ProjectSettings).
• Within Assets, you see folders like "Scenes", "Prefabs", "Sprites", and "Sources".
• Sources Directory Breakdown:
• CompositeRoot: Contains files for composition and initialization (e.g., CompositeRoot.cs, CompositionOrder.cs). This likely represents the bootstrap or entry-point that wires up the various systems/components.
• Input: Hosts classes such as ShipInput.cs, ShipInputRouter.cs, and input configurations (e.g., .inputactions). This component handles player input.
• Model: This is the core game logic layer. Subdirectories include:
• Enemies (Asteroid.cs, Nlo.cs, Enemy.cs) – managing enemy behavior.
• Simulations (e.g., BulletsSimulation, EnemiesSimulation, EnemiesSpawner, Trajectory) – governing dynamic in-game simulations.
• Other model files for ship movement, collisions (CollisionsRecords.cs), physics routing, timers, and other gameplay mechanics.
• Weapon: Manages different types of weapon implementations (Bullet.cs, DefaultGun.cs, LaserGun.cs, LaserGunRollback.cs).
• View: Contains view factories and UI-related scripts (e.g., BulletsViewFactory.cs, EnemiesViewFactory.cs, EndGameWindowView.cs, ShipDebugUIView.cs). This layer is responsible for how game state is visually represented, bridging the gap between the model and the Unity scene objects.
• Other Directories:
• Prefabs and Scenes: Represent Unity scene contents. For example, prefabs for Asteroid, Bullet, Laser, etc., and the SampleScene for gameplay.
a. Main Components:
• Composite Root/Composition Layer: Acts as the initializer and dependency configuration center.
• Input Layer: Handles player actions (keyboard, mouse, or controller inputs) and passes them to the game model.
• Model Layer: Contains the game’s core logic, including:
• Entities: Ship, Enemies (Asteroid, Nlo, etc.), and Weapons.
• Simulations: Bullet trajectories, enemy spawning, collision handling, and physics routing.
• Configuration and State Management (via files like Config.cs, Timers.cs, etc.).
• View Layer: Manages UI and visual representations (factories for spawning views, Debug UI, End Game windows, etc.).
• Unity-specific Components: Scenes, Prefabs, Input System configuration, and related project assets.
b. Relationships and Interactions:
• The Composite Root initializes and wires together the Input, Model, and View components.
• User inputs captured by the Input layer (e.g., ShipInput) are routed via a ShipInputRouter to update the Model.
• The Model processes inputs, runs simulations (e.g., enemy behaviors, bullet trajectories), and updates its state.
• Changes in the Model are reflected by the View layer, via factories (like BulletsViewFactory and EnemiesViewFactory) that instantiate or update visual prefabs.
• Additionally, communication between model components (physics events, collision records, timers) is likely coordinated through internal messaging patterns (such as PhysicsEventsBroadcaster).
c. Architectural Patterns & Design Principles:
• Separation of Concerns: Clearly delineated layers (Input, Model, View) that allow independent development and testing.
• Composition over Inheritance: The use of a CompositeRoot and non-MonoBehaviour classes illustrates a preference for composition.
• Modularity: Individual model subcomponents (Enemies, Weapons, Simulation, Physics) are isolated for easier refactoring and testing.
d. Relevant Technologies & Frameworks:
• Unity Engine: Underlying game engine (shown by folders like Assets, Scenes, Prefabs).
• Unity Input System: Evident from the Input configuration files (.inputsettings, .inputactions).
• C# Scripts: For game logic, simulation, and view management (all under Assets/Sources).