Class MeleeAvoidObstacleTask
java.lang.Object
com.deco2800.game.ai.tasks.DefaultTask
com.deco2800.game.components.tasks.MeleeAvoidObstacleTask
- All Implemented Interfaces:
PriorityTask,Task
task that gets enemies to avoid obstacles. The algorithm is pretty simple:
task is given a random rotation direction (right or left) at startup and on collision with a non-destroyable object that
impedes movement, it will turn that direction and walk until (a) collision ends or (b) another collision occurs, at which
point they will turn in that same direction again.
After collision ends, task rotates in the inverse direction to its given rotation direction and walks for 10 update() cycles
before resuming normal pathfinding. This will (hopefully) prevent getting stuck repeatedly in the same 'bucket'
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.deco2800.game.ai.tasks.Task
Task.Status -
Field Summary
Fields inherited from class com.deco2800.game.ai.tasks.DefaultTask
owner, status -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgets the priority of this task.voidmust be called after task, component, and entity are attached registers collision listeners for the entityvoidstart()set a new target perpendicular to the direction of the previous target Note this is only called when priority is highest (i.e.voidstop()Stop the task immediately.voidupdate()update checks if the new direction has run into any obstacles that stopped movement, and adjusts direction if necessaryMethods inherited from class com.deco2800.game.ai.tasks.DefaultTask
create, getStatus
-
Constructor Details
-
MeleeAvoidObstacleTask
initialise the avoidance task. Task should get its entity registered using registerEntity() after creation (must be done after creation as the entity doesn't exist yet- Parameters:
target- the Entity this NPC is trying to reach
-
-
Method Details
-
registerEntityEvents
public void registerEntityEvents()must be called after task, component, and entity are attached registers collision listeners for the entity -
start
public void start()set a new target perpendicular to the direction of the previous target Note this is only called when priority is highest (i.e. the entity is already not moving)- Specified by:
startin interfaceTask- Overrides:
startin classDefaultTask
-
update
public void update()update checks if the new direction has run into any obstacles that stopped movement, and adjusts direction if necessary- Specified by:
updatein interfaceTask- Overrides:
updatein classDefaultTask
-
getPriority
public int getPriority()gets the priority of this task.- Specified by:
getPriorityin interfacePriorityTask- Returns:
- -1 if it's not nighttime, otherwise active priority if active, inactive priority if inactive
-
stop
public void stop()Description copied from interface:TaskStop the task immediately. This can be called at any time by the AI controller.- Specified by:
stopin interfaceTask- Overrides:
stopin classDefaultTask
-