Add some null checks, and fix typos in comments
This commit is contained in:
parent
2d7024275f
commit
f3ad6c0ffa
1 changed files with 21 additions and 17 deletions
|
@ -20,7 +20,6 @@ import com.redstrate.watersymbol.*;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
public class GameScreen implements Screen {
|
||||
private final WaterSymbol game;
|
||||
|
@ -83,13 +82,13 @@ public class GameScreen implements Screen {
|
|||
|
||||
units.add(enemy2);
|
||||
|
||||
|
||||
playerTexture = new Texture(Gdx.files.internal("player.png"));
|
||||
playerSprite = new Sprite(playerTexture);
|
||||
|
||||
arrowAtlas = new TextureAtlas("test.atlas");
|
||||
|
||||
startNewTeamTurn(Unit.Team.Player);
|
||||
smoothlyTransitionCamera(new Vector3(currentUnit.positionX * 32, currentUnit.positionY * 32, 0));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -265,7 +264,7 @@ public class GameScreen implements Screen {
|
|||
playerSprite.draw(game.batch);
|
||||
}
|
||||
|
||||
// early exit, since we want the camera to finish it's nice transistion
|
||||
// early exit, since we want the camera to finish its nice transition
|
||||
if(currentlyTransitionCamera) {
|
||||
game.batch.end();
|
||||
return;
|
||||
|
@ -366,21 +365,26 @@ public class GameScreen implements Screen {
|
|||
}
|
||||
}
|
||||
|
||||
// if we're already next to them, why move?
|
||||
if(isAdjacent(currentUnit, closestUnit)) {
|
||||
currentlyAwaitingAuxilaryAction = true;
|
||||
} else {
|
||||
// now that we have the closest unit, let's path to it.
|
||||
ArrayList<Vector2> path = AStar.path(new Vector2(currentUnit.positionX, currentUnit.positionY), new Vector2((float) closestUnit.positionX, (float) closestUnit.positionY), getCollision());
|
||||
if (path != null) {
|
||||
Collections.reverse(path);
|
||||
List<Vector2> realPath = path.subList(0, Math.min(currentUnit.maxDistance, path.size()));
|
||||
if(closestUnit != null) {
|
||||
// if we're already next to them, why move?
|
||||
if (isAdjacent(currentUnit, closestUnit)) {
|
||||
currentlyAwaitingAuxilaryAction = true;
|
||||
} else {
|
||||
// now that we have the closest unit, lets path to it.
|
||||
ArrayList<Vector2> path = AStar.path(new Vector2(currentUnit.positionX, currentUnit.positionY), new Vector2((float) closestUnit.positionX, (float) closestUnit.positionY), getCollision());
|
||||
if (path != null) {
|
||||
Collections.reverse(path);
|
||||
List<Vector2> realPath = path.subList(0, Math.min(currentUnit.maxDistance, path.size()));
|
||||
|
||||
// we want to grab the second to last position, since that's the "max distance" we can go, and it makes no sense
|
||||
// for units to go shorter
|
||||
Vector2 determinedPos = realPath.get(realPath.size() - 2);
|
||||
moveUnitTo((int) determinedPos.x, (int) determinedPos.y);
|
||||
// we want to grab the second to last position, since that's the "max distance" we can go, and it makes no sense
|
||||
// for units to go shorter
|
||||
Vector2 determinedPos = realPath.get(realPath.size() - 2);
|
||||
moveUnitTo((int) determinedPos.x, (int) determinedPos.y);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// TODO: this should be normal behavior if a player unit is not in "range" of an enemy unit
|
||||
advanceTurn();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,7 +401,7 @@ public class GameScreen implements Screen {
|
|||
}
|
||||
}
|
||||
|
||||
if(currentlyAwaitingAuxilaryAction) {
|
||||
if(currentlyAwaitingAuxilaryAction && currentUnit != null) {
|
||||
if (currentUnit.team == Unit.Team.Enemy) {
|
||||
Unit closestUnit = null;
|
||||
float closestDistance = 999;
|
||||
|
|
Reference in a new issue