Class PatrolTask
java.lang.Object
com.csse3200.game.ai.tasks.DefaultTask
com.csse3200.game.components.tasks.PatrolTask
- All Implemented Interfaces:
PriorityTask,Task
Task that makes an entity move through a sequence of waypoints, pausing briefly at each.
The entity patrols back and forth along its route, reversing direction when it reaches the end,
and repeats this indefinitely.
Requires the entity to have a PatrolRouteComponent which defines the set of waypoints to follow.
Note: This task only controls behaviour during the patrol itself. Resetting the entity back to
its starting waypoint (e.g. after switching from chase mode back to patrol) is handled separately
by a cooldown task. For full patrol-chase-cooldown cycles, both tasks should be added to the
entity's AITaskComponent.
-
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
ConstructorsConstructorDescriptionPatrolTask(float waitTime) Creates a patrol starting from a fixed start position. -
Method Summary
Modifier and TypeMethodDescriptionintgetIndex()Get the current index pointing to a waypoint.intReturn a low priority of 1.com.badlogic.gdx.math.Vector2Get the waypoint of current indexbooleanisMoving()Check if moving.booleanCheck patrol direction.booleanCheck if waiting.voidstart()Set up subtasks (wait, movement) and begin moving toward first waypoint.voidstop()Stop the patrol task and its current subtaskvoidupdate()Advance the patrol state.Methods inherited from class com.csse3200.game.ai.tasks.DefaultTask
create, getStatus
-
Constructor Details
-
PatrolTask
public PatrolTask(float waitTime) Creates a patrol starting from a fixed start position.- Parameters:
waitTime- specifies how long to wait at each waypoint before moving to the next.
-
-
Method Details
-
getPriority
public int getPriority()Return a low priority of 1.- Specified by:
getPriorityin interfacePriorityTask
-
start
public void start()Set up subtasks (wait, movement) and begin moving toward first waypoint.- Specified by:
startin interfaceTask- Overrides:
startin classDefaultTask
-
update
public void update()Advance the patrol state. Handles swapping between wait and movement tasks based on their status.- Specified by:
updatein interfaceTask- Overrides:
updatein classDefaultTask
-
stop
public void stop()Stop the patrol task and its current subtask- Specified by:
stopin interfaceTask- Overrides:
stopin classDefaultTask
-
isWaiting
public boolean isWaiting()Check if waiting.- Returns:
- true if currentTask is waitTask
-
isMoving
public boolean isMoving()Check if moving.- Returns:
- true if currentTask is movementTask
-
getIndex
public int getIndex()Get the current index pointing to a waypoint. -
isMovingForward
public boolean isMovingForward()Check patrol direction.- Returns:
- true for forward, otherwise false
-
getTargetWaypoint
public com.badlogic.gdx.math.Vector2 getTargetWaypoint()Get the waypoint of current index- Returns:
- target waypoint
-