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 TypeMethodDescriptionvoid
create
(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.Vector2
getSpeed()
Retrieves the movement speed of the entity.boolean
Checks if the entity has reached the target position.void
setTarget
(com.badlogic.gdx.math.Vector2 target) Sets a new target position for the movement task.void
start()
Starts the movement task by setting up the movement parameters and triggering the start event.void
stop()
Stops the movement task and resets movement-related parameters.void
update()
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:
create
in interfaceTask
- Overrides:
create
in 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:
start
in interfaceTask
- Overrides:
start
in classDefaultTask
-
update
public void update()Updates the movement task by checking if the target has been reached and handling movement changes.- Specified by:
update
in interfaceTask
- Overrides:
update
in 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:
stop
in interfaceTask
- Overrides:
stop
in 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.
-