diff --git a/core/src/com/redstrate/watersymbol/AttackAction.java b/core/src/com/redstrate/watersymbol/AttackAction.java new file mode 100644 index 0000000..c9d6944 --- /dev/null +++ b/core/src/com/redstrate/watersymbol/AttackAction.java @@ -0,0 +1,9 @@ +package com.redstrate.watersymbol; + +public class AttackAction implements UnitAction { + + @Override + public String getName() { + return "Attack"; + } +} diff --git a/core/src/com/redstrate/watersymbol/TradeAction.java b/core/src/com/redstrate/watersymbol/TradeAction.java new file mode 100644 index 0000000..08e03fd --- /dev/null +++ b/core/src/com/redstrate/watersymbol/TradeAction.java @@ -0,0 +1,9 @@ +package com.redstrate.watersymbol; + +public class TradeAction implements UnitAction { + + @Override + public String getName() { + return "Trade"; + } +} diff --git a/core/src/com/redstrate/watersymbol/UnitAction.java b/core/src/com/redstrate/watersymbol/UnitAction.java new file mode 100644 index 0000000..bec92dd --- /dev/null +++ b/core/src/com/redstrate/watersymbol/UnitAction.java @@ -0,0 +1,6 @@ +package com.redstrate.watersymbol; + +public interface UnitAction { + public String getName(); +} + diff --git a/core/src/com/redstrate/watersymbol/WaitAction.java b/core/src/com/redstrate/watersymbol/WaitAction.java new file mode 100644 index 0000000..59579fa --- /dev/null +++ b/core/src/com/redstrate/watersymbol/WaitAction.java @@ -0,0 +1,9 @@ +package com.redstrate.watersymbol; + +public class WaitAction implements UnitAction { + + @Override + public String getName() { + return "Wait"; + } +} diff --git a/core/src/com/redstrate/watersymbol/screens/GameScreen.java b/core/src/com/redstrate/watersymbol/screens/GameScreen.java index c0eaf64..1ab476d 100644 --- a/core/src/com/redstrate/watersymbol/screens/GameScreen.java +++ b/core/src/com/redstrate/watersymbol/screens/GameScreen.java @@ -1,6 +1,7 @@ package com.redstrate.watersymbol.screens; import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.Input; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; @@ -13,10 +14,9 @@ import com.badlogic.gdx.maps.tiled.TmxMapLoader; import com.badlogic.gdx.maps.tiled.renderers.OrthogonalTiledMapRenderer; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.utils.Array; import com.badlogic.gdx.utils.ScreenUtils; -import com.redstrate.watersymbol.AStar; -import com.redstrate.watersymbol.Unit; -import com.redstrate.watersymbol.WaterSymbol; +import com.redstrate.watersymbol.*; import java.util.ArrayList; import java.util.Collections; @@ -44,6 +44,8 @@ public class GameScreen implements Screen { boolean currentlyTakingAction = false; List currentMovementList; + boolean currentlyAwaitingAuxilaryAction = false; + GameScreen(WaterSymbol game) { this.game = game; @@ -123,6 +125,31 @@ public class GameScreen implements Screen { } } + boolean isAdjacent(Unit a, Unit b) { + return Vector2.dst(a.positionX, a.positionY, b.positionX, b.positionY) <= 1.0; + } + + List getAvailableActionsForPosition(int x, int y) { + ArrayList actions = new ArrayList<>(); + + for(Unit unit : units) { + if(unit.positionX == x && unit.positionY == y) { + if(unit.team != currentUnit.team) { + actions.add(new AttackAction()); + } else { + // you can't trade with yourself! + if(unit != currentUnit) { + actions.add(new TradeAction()); + } + } + } + } + + actions.add(new WaitAction()); + + return actions; + } + List getCollision() { ArrayList collisions = new ArrayList<>(); for(Unit unit : units) { @@ -134,6 +161,10 @@ public class GameScreen implements Screen { return collisions; } + void executeAction(UnitAction action) { + advanceTurn(); + } + @Override public void render(float delta) { ScreenUtils.clear(0, 0, 0.2f, 1); @@ -155,7 +186,7 @@ public class GameScreen implements Screen { if(currentTurnTeam == Unit.Team.Player && currentUnit != null) { // player is trying to move - if (Gdx.input.isButtonPressed(0)) { + if (Gdx.input.isButtonPressed(0) && !currentlyAwaitingAuxilaryAction) { hasStartedMoving = true; Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); @@ -245,7 +276,29 @@ public class GameScreen implements Screen { currentUnit.positionY = (int) nextMove.y; } else { currentlyTakingAction = false; - advanceTurn(); + currentlyAwaitingAuxilaryAction = true; + } + } + + if(currentlyAwaitingAuxilaryAction) { + Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0); + + camera.unproject(mousePos); + + double newX = Math.floor(mousePos.x); + double newY = Math.floor(mousePos.y); + + int newFixedX = (int) (newX / 32.0); + int newFixedY = (int) (newY / 32.0); + + List actions = getAvailableActionsForPosition(newFixedX, newFixedY); + for(int i = 0; i < actions.size(); i++) { + game.font.draw(game.batch, (i + 1) + ": " + actions.get(i).getName(), (float) newX, (float)newY + (i * 32)); + + if(Gdx.input.isKeyPressed(Input.Keys.NUM_1 + i)) { + currentlyAwaitingAuxilaryAction = false; + executeAction(actions.get(i)); + } } }