Class ProjectileComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.combat.ProjectileComponent
All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable

public class ProjectileComponent extends Component
The ProjectileComponent class defines the behavior of a projectile entity in the game. It handles movement, duration, impact, and destruction of the projectile.
  • Constructor Details

    • ProjectileComponent

      public ProjectileComponent(float duration)
      Constructs a ProjectileComponent with a specified duration.
      Parameters:
      duration - The duration for which the projectile remains active before self-destruction.
  • Method Details

    • create

      public void create()
      Initializes the ProjectileComponent when it is created. Sets up physics properties, event listeners, and schedules the projectile's destruction.
      Overrides:
      create in class Component
    • setTargetDirection

      public void setTargetDirection(com.badlogic.gdx.math.Vector2 target)
      Sets the target direction for the projectile and applies velocity to its physics body.
      Parameters:
      target - The target position to which the projectile should be directed.
    • setConstantVelocity

      public void setConstantVelocity(boolean constantVelocity)
    • setSpeed

      public void setSpeed(com.badlogic.gdx.math.Vector2 speed)
      Sets the speed of the projectile.
      Parameters:
      speed - The new speed vector for the projectile.
    • update

      public void update()
      Updates the projectile's behavior, destroying it once its impact animation is finished.
      Overrides:
      update in class Component
    • setDestroyOnImpact

      public void setDestroyOnImpact(boolean destroyOnImpact)
    • getVelocity

      public com.badlogic.gdx.math.Vector2 getVelocity()
      Gets the velocity vector of the projectile.
      Returns:
      The velocity vector of the projectile.
    • setVelocity

      public void setVelocity(com.badlogic.gdx.math.Vector2 velocity)
      Set velocity without triggering movement, used for setting knockback velocity
      Parameters:
      velocity - velocity to set