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 TypeMethodDescriptionint
getIndex()
Get the current index pointing to a waypoint.int
Return a low priority of 1.com.badlogic.gdx.math.Vector2
Get the waypoint of current indexboolean
isMoving()
Check if moving.boolean
Check patrol direction.boolean
Check if waiting.void
start()
Set up subtasks (wait, movement) and begin moving toward first waypoint.void
stop()
Stop the patrol task and its current subtaskvoid
update()
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:
getPriority
in interfacePriorityTask
-
start
public void start()Set up subtasks (wait, movement) and begin moving toward first waypoint.- Specified by:
start
in interfaceTask
- Overrides:
start
in classDefaultTask
-
update
public void update()Advance the patrol state. Handles swapping between wait and movement tasks based on their status.- Specified by:
update
in interfaceTask
- Overrides:
update
in classDefaultTask
-
stop
public void stop()Stop the patrol task and its current subtask- Specified by:
stop
in interfaceTask
- Overrides:
stop
in 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
-