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
The ProjectileComponent class defines the behavior of a projectile entity in the game.
It handles movement, duration, impact, and destruction of the projectile.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionProjectileComponent
(float duration) Constructs a ProjectileComponent with a specified duration. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Initializes the ProjectileComponent when it is created.com.badlogic.gdx.math.Vector2
Gets the velocity vector of the projectile.void
setConstantVelocity
(boolean constantVelocity) void
setDestroyOnImpact
(boolean destroyOnImpact) void
setSpeed
(com.badlogic.gdx.math.Vector2 speed) Sets the speed of the projectile.void
setTargetDirection
(com.badlogic.gdx.math.Vector2 target) Sets the target direction for the projectile and applies velocity to its physics body.void
setVelocity
(com.badlogic.gdx.math.Vector2 velocity) Set velocity without triggering movement, used for setting knockback velocityvoid
update()
Updates the projectile's behavior, destroying it once its impact animation is finished.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, read, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, write
-
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. -
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. -
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
-