Add framework unit actions
This commit is contained in:
parent
628a06d097
commit
5ab8a6c388
5 changed files with 91 additions and 5 deletions
9
core/src/com/redstrate/watersymbol/AttackAction.java
Normal file
9
core/src/com/redstrate/watersymbol/AttackAction.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package com.redstrate.watersymbol;
|
||||
|
||||
public class AttackAction implements UnitAction {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Attack";
|
||||
}
|
||||
}
|
9
core/src/com/redstrate/watersymbol/TradeAction.java
Normal file
9
core/src/com/redstrate/watersymbol/TradeAction.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package com.redstrate.watersymbol;
|
||||
|
||||
public class TradeAction implements UnitAction {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Trade";
|
||||
}
|
||||
}
|
6
core/src/com/redstrate/watersymbol/UnitAction.java
Normal file
6
core/src/com/redstrate/watersymbol/UnitAction.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package com.redstrate.watersymbol;
|
||||
|
||||
public interface UnitAction {
|
||||
public String getName();
|
||||
}
|
||||
|
9
core/src/com/redstrate/watersymbol/WaitAction.java
Normal file
9
core/src/com/redstrate/watersymbol/WaitAction.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package com.redstrate.watersymbol;
|
||||
|
||||
public class WaitAction implements UnitAction {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Wait";
|
||||
}
|
||||
}
|
|
@ -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<Vector2> 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<UnitAction> getAvailableActionsForPosition(int x, int y) {
|
||||
ArrayList<UnitAction> 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<Vector2> getCollision() {
|
||||
ArrayList<Vector2> 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<UnitAction> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue