Add proper cursor system, and add discoloration when a unit has moved
This commit is contained in:
parent
08978c32ec
commit
36ba603933
2 changed files with 268 additions and 209 deletions
|
@ -12,4 +12,6 @@ public class Unit {
|
||||||
}
|
}
|
||||||
public Team team;
|
public Team team;
|
||||||
public int maxDistance = 5;
|
public int maxDistance = 5;
|
||||||
|
|
||||||
|
public boolean hasTakenAction = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,21 +149,32 @@ public class GameScreen implements Screen {
|
||||||
|
|
||||||
void startNewTeamTurn(Unit.Team team) {
|
void startNewTeamTurn(Unit.Team team) {
|
||||||
currentTurnTeam = team;
|
currentTurnTeam = team;
|
||||||
currentUnitIndex = 0;
|
|
||||||
|
|
||||||
|
for(Unit unit : units) {
|
||||||
|
if(unit.team == team) {
|
||||||
|
unit.hasTakenAction = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentUnitIndex = 0;
|
||||||
getNextUnit();
|
getNextUnit();
|
||||||
|
|
||||||
if(currentUnit != null) {
|
if(currentUnit != null) {
|
||||||
cursorX = currentUnit.positionX;
|
|
||||||
cursorY = currentUnit.positionY;
|
|
||||||
smoothlyTransitionCamera(new Vector3(currentUnit.positionX * 16, currentUnit.positionY * 16, 0));
|
smoothlyTransitionCamera(new Vector3(currentUnit.positionX * 16, currentUnit.positionY * 16, 0));
|
||||||
|
|
||||||
|
// reset cursor position
|
||||||
|
if(team == Unit.Team.Player) {
|
||||||
|
cursorX = currentUnit.positionX;
|
||||||
|
cursorY = currentUnit.positionY;
|
||||||
|
currentUnit = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateUnits() {
|
void updateUnits() {
|
||||||
units.removeIf(u -> u.health <= 0);
|
units.removeIf(u -> u.health <= 0);
|
||||||
|
|
||||||
// then check if theres a win or lose condition
|
// then check if there's a win or lose condition
|
||||||
long numberOfPlayers = units.stream().filter(u -> u.team == Unit.Team.Player).count();
|
long numberOfPlayers = units.stream().filter(u -> u.team == Unit.Team.Player).count();
|
||||||
long numberOfEnemies = units.stream().filter(u -> u.team == Unit.Team.Enemy).count();
|
long numberOfEnemies = units.stream().filter(u -> u.team == Unit.Team.Enemy).count();
|
||||||
|
|
||||||
|
@ -174,6 +185,13 @@ public class GameScreen implements Screen {
|
||||||
gameWin();
|
gameWin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean hasAllUnitsTakenAction() {
|
||||||
|
long numberOfPlayers = units.stream().filter(u -> u.team == currentTurnTeam).count();
|
||||||
|
long numberOfUnitsTired = units.stream().filter(u -> u.hasTakenAction).count();
|
||||||
|
|
||||||
|
return numberOfPlayers == numberOfUnitsTired;
|
||||||
|
}
|
||||||
|
|
||||||
void gameOver() {
|
void gameOver() {
|
||||||
game.setScreen(new GameOverMenuScreen(game));
|
game.setScreen(new GameOverMenuScreen(game));
|
||||||
dispose();
|
dispose();
|
||||||
|
@ -188,18 +206,20 @@ public class GameScreen implements Screen {
|
||||||
void advanceTurn() {
|
void advanceTurn() {
|
||||||
updateUnits();
|
updateUnits();
|
||||||
|
|
||||||
currentUnitIndex++;
|
if(currentTurnTeam == Unit.Team.Player) {
|
||||||
getNextUnit();
|
if(hasAllUnitsTakenAction()) {
|
||||||
|
|
||||||
if(currentUnit == null) {
|
|
||||||
if(currentTurnTeam == Unit.Team.Player) {
|
|
||||||
startNewTeamTurn(Unit.Team.Enemy);
|
startNewTeamTurn(Unit.Team.Enemy);
|
||||||
} else if(currentTurnTeam == Unit.Team.Enemy) {
|
|
||||||
currentTurn++;
|
|
||||||
startNewTeamTurn(Unit.Team.Player);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
smoothlyTransitionCamera(new Vector3(currentUnit.positionX * 16, currentUnit.positionY * 16, 0));
|
currentUnitIndex++;
|
||||||
|
getNextUnit();
|
||||||
|
|
||||||
|
if(currentUnit == null) {
|
||||||
|
currentTurn++;
|
||||||
|
startNewTeamTurn(Unit.Team.Player);
|
||||||
|
} else {
|
||||||
|
smoothlyTransitionCamera(new Vector3(currentUnit.positionX * 16, currentUnit.positionY * 16, 0));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,6 +383,12 @@ public class GameScreen implements Screen {
|
||||||
for(Unit unit : units) {
|
for(Unit unit : units) {
|
||||||
TextureRegion currentFrame = playerIdleAnimation.getKeyFrame(stateTime, true);
|
TextureRegion currentFrame = playerIdleAnimation.getKeyFrame(stateTime, true);
|
||||||
|
|
||||||
|
if(unit.hasTakenAction) {
|
||||||
|
game.batch.setColor(0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
} else {
|
||||||
|
game.batch.setColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
game.batch.draw(currentFrame, unit.positionX * 16, unit.positionY * 16);
|
game.batch.draw(currentFrame, unit.positionX * 16, unit.positionY * 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,208 +398,220 @@ public class GameScreen implements Screen {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentTurnTeam == Unit.Team.Player && currentUnit != null) {
|
if(currentTurnTeam == Unit.Team.Player) {
|
||||||
// player is trying to move
|
if(currentUnit == null) {
|
||||||
if (Gdx.input.isButtonPressed(0) && !currentlyAwaitingAuxilaryAction) {
|
if (Gdx.input.isKeyPressed(Input.Keys.ENTER) || Gdx.input.isButtonPressed(0)) {
|
||||||
hasStartedMoving = true;
|
for (Unit unit : units) {
|
||||||
|
if (unit.team == Unit.Team.Player && !unit.hasTakenAction) {
|
||||||
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
if (cursorX == unit.positionX && cursorY == unit.positionY) {
|
||||||
|
currentUnit = unit;
|
||||||
camera.unproject(mousePos);
|
}
|
||||||
|
|
||||||
double newX = Math.floor(mousePos.x);
|
|
||||||
double newY = Math.floor(mousePos.y);
|
|
||||||
|
|
||||||
int newFixedX = (int) (newX / 16.0);
|
|
||||||
int newFixedY = (int) (newY / 16.0);
|
|
||||||
|
|
||||||
ArrayList<Vector2> path = AStar.path(new Vector2(currentUnit.positionX, currentUnit.positionY), new Vector2((float) newFixedX, (float) newFixedY), getCollision(), tiledMap);
|
|
||||||
if (path != null && path.size() > 1) {
|
|
||||||
Collections.reverse(path);
|
|
||||||
List<Vector2> realPath = path.subList(0, Math.min(currentUnit.maxDistance, path.size()));
|
|
||||||
|
|
||||||
// we start at index 1 since there's no point in drawing an arrow over the player
|
|
||||||
for (int i = 1; i < realPath.size() - 1; i++) {
|
|
||||||
Vector2 previousPosition = realPath.get(i - 1);
|
|
||||||
Vector2 newPosition = realPath.get(i);
|
|
||||||
Vector2 nextPosition = realPath.get(i + 1);
|
|
||||||
|
|
||||||
// we want to grab two directions, first is our "entrance" and then our "exit". of course arrows that are just a position don't exist
|
|
||||||
Direction entrance = getFromDelta(new Vector2(newPosition.x - previousPosition.x, newPosition.y - previousPosition.y));
|
|
||||||
Direction exit = getFromDelta(new Vector2(newPosition.x - nextPosition.x, newPosition.y - nextPosition.y));
|
|
||||||
|
|
||||||
TextureRegion spriteRegion = null;
|
|
||||||
TextureRegion leftSprite = null;
|
|
||||||
TextureRegion rightSprite = null;
|
|
||||||
|
|
||||||
// TODO: condense duplicate branches
|
|
||||||
|
|
||||||
// handle straights
|
|
||||||
if(entrance == Direction.Bottom && exit == Direction.Top) {
|
|
||||||
spriteRegion = arrowSpritesheet.getUpDown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(entrance == Direction.Top && exit == Direction.Bottom) {
|
|
||||||
spriteRegion = arrowSpritesheet.getUpDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.Left && exit == Direction.Right) {
|
|
||||||
spriteRegion = arrowSpritesheet.getLeftRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.Right && exit == Direction.Left) {
|
|
||||||
spriteRegion = arrowSpritesheet.getLeftRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle crosses
|
|
||||||
if(entrance == Direction.TopLeft && exit == Direction.BottomRight) {
|
|
||||||
spriteRegion = arrowSpritesheet.getDiagDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.TopLeft && exit == Direction.TopLeft) {
|
|
||||||
spriteRegion = arrowSpritesheet.getDiagDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.BottomLeft && exit == Direction.BottomLeft) {
|
|
||||||
spriteRegion = arrowSpritesheet.getDiagUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.BottomLeft && exit == Direction.TopRight) {
|
|
||||||
spriteRegion = arrowSpritesheet.getDiagUp();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.BottomRight && exit == Direction.TopLeft) {
|
|
||||||
spriteRegion = arrowSpritesheet.getDiagDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.TopRight && exit == Direction.BottomLeft) {
|
|
||||||
spriteRegion = arrowSpritesheet.getDiagDown();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(spriteRegion == arrowSpritesheet.getDiagDown()) {
|
|
||||||
leftSprite = arrowSpritesheet.getCornerTopRight();
|
|
||||||
rightSprite = arrowSpritesheet.getCornerBottomLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(spriteRegion == arrowSpritesheet.getDiagUp()) {
|
|
||||||
leftSprite = arrowSpritesheet.getCornerBottomRight();
|
|
||||||
rightSprite = arrowSpritesheet.getCornerTopLeft();
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle bends
|
|
||||||
if(entrance == Direction.BottomRight && exit == Direction.Top) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendBottomRightToTop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.Top && exit == Direction.BottomRight) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendBottomRightToTop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.BottomLeft && exit == Direction.Top) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendBottomLeftToTop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.Top && exit == Direction.BottomLeft) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendBottomLeftToTop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.TopLeft && exit == Direction.Bottom) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendTopLeftToBottom();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.Bottom && exit == Direction.TopLeft) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendTopLeftToBottom();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.TopRight && exit == Direction.Bottom) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendTopRightToBottom();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.Bottom && exit == Direction.TopRight) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendTopRightToBottom();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.TopLeft && exit == Direction.Right) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendTopLeftToRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.Right && exit == Direction.TopLeft) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendTopLeftToRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.BottomLeft && exit == Direction.Right) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendBottomLeftToRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(entrance == Direction.Right && exit == Direction.BottomLeft) {
|
|
||||||
spriteRegion = arrowSpritesheet.getBendBottomLeftToRight();
|
|
||||||
}
|
|
||||||
|
|
||||||
//game.font.draw(game.batch, entrance.toString() + " to " + exit.toString(), newPosition.x * 16, newPosition.y * 16);
|
|
||||||
|
|
||||||
if (spriteRegion != null) {
|
|
||||||
game.batch.draw(spriteRegion, newPosition.x * 16, newPosition.y * 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(leftSprite != null) {
|
|
||||||
game.batch.draw(leftSprite, (newPosition.x - 1) * 16, newPosition.y * 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(rightSprite != null) {
|
|
||||||
game.batch.draw(rightSprite, (newPosition.x + 1) * 16, newPosition.y * 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// now we want to draw the arrow or the "end" point.
|
|
||||||
Vector2 secondToLastPosition = realPath.get(realPath.size() - 2);
|
|
||||||
Vector2 lastPosition = realPath.get(realPath.size() - 1);
|
|
||||||
|
|
||||||
Direction exit = getFromDelta(new Vector2(lastPosition.x - secondToLastPosition.x, lastPosition.y - secondToLastPosition.y));
|
|
||||||
|
|
||||||
TextureRegion spriteRegion = null;
|
|
||||||
|
|
||||||
switch(exit) {
|
|
||||||
case Top:
|
|
||||||
spriteRegion = arrowSpritesheet.getArrowFromTop();
|
|
||||||
break;
|
|
||||||
case Bottom:
|
|
||||||
spriteRegion = arrowSpritesheet.getArrowFromBottom();
|
|
||||||
break;
|
|
||||||
case Left:
|
|
||||||
spriteRegion = arrowSpritesheet.getArrowFromLeft();
|
|
||||||
break;
|
|
||||||
case Right:
|
|
||||||
spriteRegion = arrowSpritesheet.getArrowFromRight();
|
|
||||||
break;
|
|
||||||
case TopLeft:
|
|
||||||
spriteRegion = arrowSpritesheet.getArrowFromTopLeft();
|
|
||||||
break;
|
|
||||||
case TopRight:
|
|
||||||
spriteRegion = arrowSpritesheet.getArrowFromTopRight();
|
|
||||||
break;
|
|
||||||
case BottomLeft:
|
|
||||||
spriteRegion = arrowSpritesheet.getArrowFromBottomLeft();
|
|
||||||
break;
|
|
||||||
case BottomRight:
|
|
||||||
spriteRegion = arrowSpritesheet.getArrowFromBottomRight();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(spriteRegion != null) {
|
|
||||||
game.batch.draw(spriteRegion, lastPosition.x * 16, lastPosition.y * 16);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (hasStartedMoving) {
|
} else {
|
||||||
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
// player is trying to move
|
||||||
|
if (Gdx.input.isButtonPressed(0) && !currentlyAwaitingAuxilaryAction) {
|
||||||
|
hasStartedMoving = true;
|
||||||
|
|
||||||
camera.unproject(mousePos);
|
Vector3 mousePos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
|
||||||
|
|
||||||
double newX = Math.floor(mousePos.x);
|
camera.unproject(mousePos);
|
||||||
double newY = Math.floor(mousePos.y);
|
|
||||||
|
|
||||||
moveUnitTo((int) (newX / 16.0), (int) (newY / 16.0));
|
double newX = Math.floor(mousePos.x);
|
||||||
|
double newY = Math.floor(mousePos.y);
|
||||||
|
|
||||||
hasStartedMoving = false;
|
int newFixedX = (int) (newX / 16.0);
|
||||||
|
int newFixedY = (int) (newY / 16.0);
|
||||||
|
|
||||||
|
ArrayList<Vector2> path = AStar.path(new Vector2(currentUnit.positionX, currentUnit.positionY), new Vector2((float) newFixedX, (float) newFixedY), getCollision(), tiledMap);
|
||||||
|
if (path != null && path.size() > 1) {
|
||||||
|
Collections.reverse(path);
|
||||||
|
List<Vector2> realPath = path.subList(0, Math.min(currentUnit.maxDistance, path.size()));
|
||||||
|
|
||||||
|
// we start at index 1 since there's no point in drawing an arrow over the player
|
||||||
|
for (int i = 1; i < realPath.size() - 1; i++) {
|
||||||
|
Vector2 previousPosition = realPath.get(i - 1);
|
||||||
|
Vector2 newPosition = realPath.get(i);
|
||||||
|
Vector2 nextPosition = realPath.get(i + 1);
|
||||||
|
|
||||||
|
// we want to grab two directions, first is our "entrance" and then our "exit". of course arrows that are just a position don't exist
|
||||||
|
Direction entrance = getFromDelta(new Vector2(newPosition.x - previousPosition.x, newPosition.y - previousPosition.y));
|
||||||
|
Direction exit = getFromDelta(new Vector2(newPosition.x - nextPosition.x, newPosition.y - nextPosition.y));
|
||||||
|
|
||||||
|
TextureRegion spriteRegion = null;
|
||||||
|
TextureRegion leftSprite = null;
|
||||||
|
TextureRegion rightSprite = null;
|
||||||
|
|
||||||
|
// TODO: condense duplicate branches
|
||||||
|
|
||||||
|
// handle straights
|
||||||
|
if(entrance == Direction.Bottom && exit == Direction.Top) {
|
||||||
|
spriteRegion = arrowSpritesheet.getUpDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.Top && exit == Direction.Bottom) {
|
||||||
|
spriteRegion = arrowSpritesheet.getUpDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.Left && exit == Direction.Right) {
|
||||||
|
spriteRegion = arrowSpritesheet.getLeftRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.Right && exit == Direction.Left) {
|
||||||
|
spriteRegion = arrowSpritesheet.getLeftRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle crosses
|
||||||
|
if(entrance == Direction.TopLeft && exit == Direction.BottomRight) {
|
||||||
|
spriteRegion = arrowSpritesheet.getDiagDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.TopLeft && exit == Direction.TopLeft) {
|
||||||
|
spriteRegion = arrowSpritesheet.getDiagDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.BottomLeft && exit == Direction.BottomLeft) {
|
||||||
|
spriteRegion = arrowSpritesheet.getDiagUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.BottomLeft && exit == Direction.TopRight) {
|
||||||
|
spriteRegion = arrowSpritesheet.getDiagUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.BottomRight && exit == Direction.TopLeft) {
|
||||||
|
spriteRegion = arrowSpritesheet.getDiagDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.TopRight && exit == Direction.BottomLeft) {
|
||||||
|
spriteRegion = arrowSpritesheet.getDiagDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(spriteRegion == arrowSpritesheet.getDiagDown()) {
|
||||||
|
leftSprite = arrowSpritesheet.getCornerTopRight();
|
||||||
|
rightSprite = arrowSpritesheet.getCornerBottomLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(spriteRegion == arrowSpritesheet.getDiagUp()) {
|
||||||
|
leftSprite = arrowSpritesheet.getCornerBottomRight();
|
||||||
|
rightSprite = arrowSpritesheet.getCornerTopLeft();
|
||||||
|
}
|
||||||
|
|
||||||
|
// handle bends
|
||||||
|
if(entrance == Direction.BottomRight && exit == Direction.Top) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendBottomRightToTop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.Top && exit == Direction.BottomRight) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendBottomRightToTop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.BottomLeft && exit == Direction.Top) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendBottomLeftToTop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.Top && exit == Direction.BottomLeft) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendBottomLeftToTop();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.TopLeft && exit == Direction.Bottom) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendTopLeftToBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.Bottom && exit == Direction.TopLeft) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendTopLeftToBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.TopRight && exit == Direction.Bottom) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendTopRightToBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.Bottom && exit == Direction.TopRight) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendTopRightToBottom();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.TopLeft && exit == Direction.Right) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendTopLeftToRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.Right && exit == Direction.TopLeft) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendTopLeftToRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.BottomLeft && exit == Direction.Right) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendBottomLeftToRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
if(entrance == Direction.Right && exit == Direction.BottomLeft) {
|
||||||
|
spriteRegion = arrowSpritesheet.getBendBottomLeftToRight();
|
||||||
|
}
|
||||||
|
|
||||||
|
//game.font.draw(game.batch, entrance.toString() + " to " + exit.toString(), newPosition.x * 16, newPosition.y * 16);
|
||||||
|
|
||||||
|
if (spriteRegion != null) {
|
||||||
|
game.batch.draw(spriteRegion, newPosition.x * 16, newPosition.y * 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(leftSprite != null) {
|
||||||
|
game.batch.draw(leftSprite, (newPosition.x - 1) * 16, newPosition.y * 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(rightSprite != null) {
|
||||||
|
game.batch.draw(rightSprite, (newPosition.x + 1) * 16, newPosition.y * 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// now we want to draw the arrow or the "end" point.
|
||||||
|
Vector2 secondToLastPosition = realPath.get(realPath.size() - 2);
|
||||||
|
Vector2 lastPosition = realPath.get(realPath.size() - 1);
|
||||||
|
|
||||||
|
Direction exit = getFromDelta(new Vector2(lastPosition.x - secondToLastPosition.x, lastPosition.y - secondToLastPosition.y));
|
||||||
|
|
||||||
|
TextureRegion spriteRegion = null;
|
||||||
|
|
||||||
|
switch(exit) {
|
||||||
|
case Top:
|
||||||
|
spriteRegion = arrowSpritesheet.getArrowFromTop();
|
||||||
|
break;
|
||||||
|
case Bottom:
|
||||||
|
spriteRegion = arrowSpritesheet.getArrowFromBottom();
|
||||||
|
break;
|
||||||
|
case Left:
|
||||||
|
spriteRegion = arrowSpritesheet.getArrowFromLeft();
|
||||||
|
break;
|
||||||
|
case Right:
|
||||||
|
spriteRegion = arrowSpritesheet.getArrowFromRight();
|
||||||
|
break;
|
||||||
|
case TopLeft:
|
||||||
|
spriteRegion = arrowSpritesheet.getArrowFromTopLeft();
|
||||||
|
break;
|
||||||
|
case TopRight:
|
||||||
|
spriteRegion = arrowSpritesheet.getArrowFromTopRight();
|
||||||
|
break;
|
||||||
|
case BottomLeft:
|
||||||
|
spriteRegion = arrowSpritesheet.getArrowFromBottomLeft();
|
||||||
|
break;
|
||||||
|
case BottomRight:
|
||||||
|
spriteRegion = arrowSpritesheet.getArrowFromBottomRight();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(spriteRegion != null) {
|
||||||
|
game.batch.draw(spriteRegion, lastPosition.x * 16, lastPosition.y * 16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (hasStartedMoving) {
|
||||||
|
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);
|
||||||
|
|
||||||
|
moveUnitTo((int) (newX / 16.0), (int) (newY / 16.0));
|
||||||
|
|
||||||
|
hasStartedMoving = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,8 +683,10 @@ public class GameScreen implements Screen {
|
||||||
|
|
||||||
if(isAdjacent(closestUnit, currentUnit)) {
|
if(isAdjacent(closestUnit, currentUnit)) {
|
||||||
AttackAction action = new AttackAction(currentUnit, closestUnit);
|
AttackAction action = new AttackAction(currentUnit, closestUnit);
|
||||||
|
currentUnit.hasTakenAction = true;
|
||||||
executeAction(action);
|
executeAction(action);
|
||||||
} else {
|
} else {
|
||||||
|
currentUnit.hasTakenAction = true;
|
||||||
advanceTurn();
|
advanceTurn();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -666,13 +706,30 @@ public class GameScreen implements Screen {
|
||||||
|
|
||||||
if (Gdx.input.isKeyPressed(Input.Keys.NUM_1 + i)) {
|
if (Gdx.input.isKeyPressed(Input.Keys.NUM_1 + i)) {
|
||||||
currentlyAwaitingAuxilaryAction = false;
|
currentlyAwaitingAuxilaryAction = false;
|
||||||
|
currentUnit.hasTakenAction = true;
|
||||||
|
currentUnit = null;
|
||||||
executeAction(actions.get(i));
|
executeAction(actions.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
game.batch.draw(cursorTexture, cursorX * 16, cursorY * 16);
|
if(currentTurnTeam == Unit.Team.Player && currentUnit == null) {
|
||||||
|
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 / 16.0);
|
||||||
|
int newFixedY = (int) (newY / 16.0);
|
||||||
|
|
||||||
|
cursorX = newFixedX;
|
||||||
|
cursorY = newFixedY;
|
||||||
|
|
||||||
|
game.batch.draw(cursorTexture, cursorX * 16, cursorY * 16);
|
||||||
|
}
|
||||||
|
|
||||||
game.batch.end();
|
game.batch.end();
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue