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.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Vector;
|
|
||||||
|
|
||||||
public class GameScreen implements Screen {
|
public class GameScreen implements Screen {
|
||||||
private final WaterSymbol game;
|
private final WaterSymbol game;
|
||||||
|
@ -83,13 +82,13 @@ public class GameScreen implements Screen {
|
||||||
|
|
||||||
units.add(enemy2);
|
units.add(enemy2);
|
||||||
|
|
||||||
|
|
||||||
playerTexture = new Texture(Gdx.files.internal("player.png"));
|
playerTexture = new Texture(Gdx.files.internal("player.png"));
|
||||||
playerSprite = new Sprite(playerTexture);
|
playerSprite = new Sprite(playerTexture);
|
||||||
|
|
||||||
arrowAtlas = new TextureAtlas("test.atlas");
|
arrowAtlas = new TextureAtlas("test.atlas");
|
||||||
|
|
||||||
startNewTeamTurn(Unit.Team.Player);
|
startNewTeamTurn(Unit.Team.Player);
|
||||||
|
smoothlyTransitionCamera(new Vector3(currentUnit.positionX * 32, currentUnit.positionY * 32, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -265,7 +264,7 @@ public class GameScreen implements Screen {
|
||||||
playerSprite.draw(game.batch);
|
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) {
|
if(currentlyTransitionCamera) {
|
||||||
game.batch.end();
|
game.batch.end();
|
||||||
return;
|
return;
|
||||||
|
@ -366,21 +365,26 @@ public class GameScreen implements Screen {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if we're already next to them, why move?
|
if(closestUnit != null) {
|
||||||
if(isAdjacent(currentUnit, closestUnit)) {
|
// if we're already next to them, why move?
|
||||||
currentlyAwaitingAuxilaryAction = true;
|
if (isAdjacent(currentUnit, closestUnit)) {
|
||||||
} else {
|
currentlyAwaitingAuxilaryAction = true;
|
||||||
// now that we have the closest unit, let's path to it.
|
} else {
|
||||||
ArrayList<Vector2> path = AStar.path(new Vector2(currentUnit.positionX, currentUnit.positionY), new Vector2((float) closestUnit.positionX, (float) closestUnit.positionY), getCollision());
|
// now that we have the closest unit, lets path to it.
|
||||||
if (path != null) {
|
ArrayList<Vector2> path = AStar.path(new Vector2(currentUnit.positionX, currentUnit.positionY), new Vector2((float) closestUnit.positionX, (float) closestUnit.positionY), getCollision());
|
||||||
Collections.reverse(path);
|
if (path != null) {
|
||||||
List<Vector2> realPath = path.subList(0, Math.min(currentUnit.maxDistance, path.size()));
|
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
|
// 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
|
// for units to go shorter
|
||||||
Vector2 determinedPos = realPath.get(realPath.size() - 2);
|
Vector2 determinedPos = realPath.get(realPath.size() - 2);
|
||||||
moveUnitTo((int) determinedPos.x, (int) determinedPos.y);
|
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) {
|
if (currentUnit.team == Unit.Team.Enemy) {
|
||||||
Unit closestUnit = null;
|
Unit closestUnit = null;
|
||||||
float closestDistance = 999;
|
float closestDistance = 999;
|
||||||
|
|
Reference in a new issue