Class MovementTask
java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.MovementTask
- All Implemented Interfaces:
Task
Move to a given position, finishing when you get close enough. Requires an entity with a
PhysicsMovementComponent.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.csse3200.game.ai.tasks.Task
Task.Status -
Field Summary
Fields inherited from class com.csse3200.game.ai.tasks.DefaultTask
owner, status -
Constructor Summary
ConstructorsConstructorDescriptionMovementTask(com.badlogic.gdx.math.Vector2 target) Creates a movement task with a target position.MovementTask(com.badlogic.gdx.math.Vector2 target, float stopDistance) Creates a movement task with a target position and a specified stop distance.MovementTask(com.badlogic.gdx.math.Vector2 target, com.badlogic.gdx.math.Vector2 speed) Creates a movement task with a target position and a specified speed.MovementTask(com.badlogic.gdx.math.Vector2 target, com.badlogic.gdx.math.Vector2 speed, float stopDistance) Creates a movement task with a target position and a specified speed. -
Method Summary
Modifier and TypeMethodDescriptionvoidcreate(TaskRunner taskRunner) Retrieves the necessary components and initializes the movement task.Determines the direction of movement based on the current and target positions.com.badlogic.gdx.math.Vector2getSpeed()Retrieves the movement speed of the entity.booleanChecks if the entity has reached the target position.voidsetTarget(com.badlogic.gdx.math.Vector2 target) Sets a new target position for the movement task.voidstart()Starts the movement task by setting up the movement parameters and triggering the start event.voidstop()Stops the movement task and resets movement-related parameters.voidupdate()Updates the movement task by checking if the target has been reached and handling movement changes.Methods inherited from class com.csse3200.game.ai.tasks.DefaultTask
getStatus
-
Constructor Details
-
MovementTask
public MovementTask(com.badlogic.gdx.math.Vector2 target) Creates a movement task with a target position.- Parameters:
target- The target position to move towards.
-
MovementTask
public MovementTask(com.badlogic.gdx.math.Vector2 target, float stopDistance) Creates a movement task with a target position and a specified stop distance.- Parameters:
target- The target position to move towards.stopDistance- The distance at which the task is considered finished.
-
MovementTask
public MovementTask(com.badlogic.gdx.math.Vector2 target, com.badlogic.gdx.math.Vector2 speed) Creates a movement task with a target position and a specified speed.- Parameters:
target- The target position to move towards.speed- The movement speed of the entity.
-
MovementTask
public MovementTask(com.badlogic.gdx.math.Vector2 target, com.badlogic.gdx.math.Vector2 speed, float stopDistance) Creates a movement task with a target position and a specified speed.- Parameters:
target- The target position to move towards.speed- The movement speed of the entity.stopDistance- The distance at which the task is considered finished.
-
-
Method Details
-
create
Retrieves the necessary components and initializes the movement task.- Specified by:
createin interfaceTask- Overrides:
createin classDefaultTask- Parameters:
taskRunner- The task runner associated with this task.
-
start
public void start()Starts the movement task by setting up the movement parameters and triggering the start event.- Specified by:
startin interfaceTask- Overrides:
startin classDefaultTask
-
update
public void update()Updates the movement task by checking if the target has been reached and handling movement changes.- Specified by:
updatein interfaceTask- Overrides:
updatein classDefaultTask
-
setTarget
public void setTarget(com.badlogic.gdx.math.Vector2 target) Sets a new target position for the movement task.- Parameters:
target- The new target position.
-
stop
public void stop()Stops the movement task and resets movement-related parameters.- Specified by:
stopin interfaceTask- Overrides:
stopin classDefaultTask
-
isAtTarget
public boolean isAtTarget()Checks if the entity has reached the target position.- Returns:
- True if the entity is within the stop distance from the target, otherwise false.
-
getDirection
Determines the direction of movement based on the current and target positions.- Returns:
- The direction of movement ("right" or "left").
-
getSpeed
public com.badlogic.gdx.math.Vector2 getSpeed()Retrieves the movement speed of the entity.- Returns:
- The movement speed vector.
-