Let enemies attack the closest player units
This commit is contained in:
parent
c8dcd1e08c
commit
17913b7adb
1 changed files with 20 additions and 1 deletions
|
@ -342,8 +342,27 @@ public class GameScreen implements Screen {
|
|||
|
||||
if(currentlyAwaitingAuxilaryAction) {
|
||||
if (currentUnit.team == Unit.Team.Enemy) {
|
||||
Unit closestUnit = null;
|
||||
float closestDistance = 999;
|
||||
for(Unit unit : units) {
|
||||
if(unit.team == Unit.Team.Player) {
|
||||
float dist = Vector2.dst(unit.positionX, unit.positionY, currentUnit.positionX, currentUnit.positionY);
|
||||
if(dist < closestDistance) {
|
||||
closestUnit = unit;
|
||||
closestDistance = dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentlyAwaitingAuxilaryAction = false;
|
||||
advanceTurn();
|
||||
|
||||
if(isAdjacent(closestUnit, currentUnit)) {
|
||||
AttackAction action = new AttackAction(currentUnit, closestUnit);
|
||||
executeAction(action);
|
||||
} else {
|
||||
advanceTurn();
|
||||
}
|
||||
|
||||
} else {
|
||||
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||
|
||||
|
|
Reference in a new issue