Enemy AI now stops near core when in range; collision avoidance

This commit is contained in:
Anuken 2017-11-11 14:03:04 -05:00
parent 12aa8c406b
commit 60a5782a24
2 changed files with 17 additions and 4 deletions

View File

@ -40,7 +40,11 @@ public class Pathfind{
target = path[enemy.node];
}
//near the core, stop
if(enemy.node == path.length - 1){
vector.set(target.worldx(), target.worldy());
}
return vector.set(target.worldx(), target.worldy());

View File

@ -58,8 +58,17 @@ public class Enemy extends DestructibleEntity{
}
void move(){
Vector2 vec = Pathfind.find(this);
vec.sub(x, y).setLength(speed);
boolean nearCore = distanceTo(World.core.worldx(), World.core.worldy()) <= range - 14f;
Vector2 vec;
if(nearCore){
vec = Tmp.v2.setZero();
target = World.core.entity;
}else{
vec = Pathfind.find(this);
vec.sub(x, y).setLength(speed);
}
Array<SolidEntity> entities = Entities.getNearby(x, y, range);
@ -79,7 +88,7 @@ public class Enemy extends DestructibleEntity{
move(vec.x*Timers.delta(), vec.y*Timers.delta());
if(Timers.get(this, "target", 15)){
if(Timers.get(this, "target", 15) && !nearCore){
target = World.findTileTarget(x, y, null, range, false);
//no tile found