ProjectileActions - UQcsse3200/2024-studio-1 GitHub Wiki

ProjectileActions Component

ProjectileActions manages the movement and behavior of projectiles in the game. It includes methods to control the projectile's motion, such as shooting and stopping movement.

Class Description

The ProjectileActions class is responsible for handling projectile-related actions, including shooting in a specified direction and stopping movement. It works closely with the ProjectileAttackComponent to enable projectiles to function as intended within the game mechanics.

Key Methods:

  • void create(): Initializes the component and retrieves the associated PhysicsComponent from the entity, allowing for physical interactions in the game world.

  • void update(): Called during each frame, updates the projectile's speed if it is currently in motion. It starts 'not in motion' for this first update, the projectile is moved to the position of the parent. From here the projectile is moved in a straight line and moving var is updated to true.

  • private void updateSpeed(): Calculates and applies the necessary impulse to the projectile's body to change its speed based on the desired direction and speed.

  • void shoot(Vector2 direction, Vector2 speed):

    • Description: Moves the projectile towards a given direction.
    • Parameters:
      • Vector2 direction: The direction in which to move the projectile.
      • Vector2 speed: The speed at which to move the projectile.
  • void stopShoot():

    • Description: Stops the projectile from moving by resetting the walking direction to zero and updating speed accordingly.

Usage

The ProjectileActions class is utilized by the ProjectileAttackComponent to manage projectile motion when a weapon is fired. This component ensures that projectiles behave consistently with the game's physics and mechanics upon activation.