Class MovementTask

java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.MovementTask
All Implemented Interfaces:
Task

public class MovementTask extends DefaultTask
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

    Constructors
    Constructor
    Description
    MovementTask(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 Type
    Method
    Description
    void
    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
    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
    Starts the movement task by setting up the movement parameters and triggering the start event.
    void
    Stops the movement task and resets movement-related parameters.
    void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public void create(TaskRunner taskRunner)
      Retrieves the necessary components and initializes the movement task.
      Specified by:
      create in interface Task
      Overrides:
      create in class DefaultTask
      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 interface Task
      Overrides:
      start in class DefaultTask
    • update

      public void update()
      Updates the movement task by checking if the target has been reached and handling movement changes.
      Specified by:
      update in interface Task
      Overrides:
      update in class DefaultTask
    • 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 interface Task
      Overrides:
      stop in class DefaultTask
    • 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

      public String 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.