Alan5142/missile-toad

Software Architecture

Opened this issue · 0 comments

Missile Toad software architecture

Architecture

The game is split into two main parts: the game engine and the game itself. The
game engine is responsible for handling the game loop, rendering, and input.
The game itself is responsible for handling the game logic, such as the player
movement and enemy AI.

Game engine

The game engine is the core part, is an abstraction over Raylib and some platform-specific
code. It is responsible for handling the game loop, rendering, and input.

The game engine contains the Core classes, which are:

  • Game: The game loop, which is responsible for calling the update and
    render methods of the game.

  • Scene: A scene is a collection of entities. The game engine contains a
    stack of scenes, and the top scene is the one that is currently being
    rendered and updated. The Scene class provides utility methods to add,
    remove, and get entities. The Scene class also provides methods to
    query entities by tag or by component.

  • Entity: An entity is an object that can be attached to a scene. Entities
    by themselves do not do anything, can't be rendered, and can't be updated.
    However, components can be attached to entities to give them functionality.

  • Component: A component is an object that can be attached to an entity. A
    component contains the logic for updating or rendering an entity. Components
    can be attached to entities to give them functionality. Components can specify
    on which tick they should be updated (pre, post, fixed) or if they want to run
    on the render loop. Components can reference other components attached to the
    same entity or to other entities. Components can also reference the entity
    they are attached to. Components can be enabled or disabled.

    Component provides the following methods:

    • update: Called every tick. The tick is specified by the component.
    • render: Called every frame.
    • on_attach: Called when the component is attached to an entity.
    • on_detach: Called when the component is detached from an entity.
    • on_enable: Called when the component is enabled.
    • on_disable: Called when the component is disabled.
    • on_render: Called when the component is rendered.

    And the following properties:

    • enabled: Whether the component is enabled or not.
    • entity: The entity that the component is attached to.
    • scene: The scene that the entity is attached to.
    • tick_phase: A bit mask that specifies on which tick the component should
      be updated (pre, post, fixed).
  • Input: An abstraction over the input system. It is responsible for
    handling keyboard, mouse, and gamepad input. It can be used to check raw
    keys (such as W pressed) or actions (such as Jump pressed) and axis (such as MoveX).

  • Renderer: An abstraction over the rendering system. It is responsible for
    handling the rendering of sprites, text, and shapes. It can be used to
    render sprites, text, and shapes. It's highly coupled with the AssetManager
    class, which is responsible for loading assets such as textures and fonts.

  • AssetManager: An abstraction over the asset loading system. It is
    responsible for loading assets such as textures and fonts.

  • AudioManager: An abstraction over the audio system. It is responsible for
    playing audio.

  • SceneManager: An abstraction over the scene system. It is responsible for
    handling the scene stack and the current scene.

The game engine also contains some classes that depend on the core classes to provide
more functionality:

  • SpriteRenderer: A component that renders a sprite.
  • TextRenderer: A component that renders text.
  • ShapeRenderer: A component that renders shapes.
  • InputComponent: A component that provides an integration between the input
    system and the entity system. It also cleans itself up when the entity is
    destroyed.
  • AudioComponent: A component that provides an integration between the audio
    system and the entity system.
  • CollisionComponent: A component that provides an integration between the
    collision system and the entity system.
  • TimerComponent: Provides a timer that can be used to run code after a
    certain amount of time. This functionality is provided by reading the delta time
    from the game engine.
  • PhysicsComponent: A component that provides a rigid body that can be used
    to move an entity around the scene.
  • AnimationComponent: A component that provides an animation that can be used
    to animate an entity in the scene (using the sprite renderer).

Game

The game is the actual game. It is responsible for handling the game logic,
such as the player movement and enemy AI. It is implemented using the game
engine.

The game contains the following classes:

  • PlayerComponent: Connects various components to create the player entity.
    For example, it connects the InputComponent to the PhysicsComponent to
    move the player.
  • EnemyComponent: Connects various components to create the enemy entity.
    For example, it connects the PhysicsComponent to the AudioComponent to
    play a sound when the enemy dies.
  • MissileComponent: Connects various components to create the missile entity.
  • EnemyAIComponent: A component that controls the enemy AI. It is responsible
    for moving the enemy towards the player.

DOD:

  • An editable UML diagram about the Graphic Engine