From 17913b7adb23d6e0ac0d22765b49ef6d79f5d5cc Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 1 May 2022 19:21:02 -0400 Subject: [PATCH] Let enemies attack the closest player units --- .../watersymbol/screens/GameScreen.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/core/src/com/redstrate/watersymbol/screens/GameScreen.java b/core/src/com/redstrate/watersymbol/screens/GameScreen.java index 6b48f9c..4297cc1 100644 --- a/core/src/com/redstrate/watersymbol/screens/GameScreen.java +++ b/core/src/com/redstrate/watersymbol/screens/GameScreen.java @@ -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);