1
Fork 0

Add some null checks, and fix typos in comments

This commit is contained in:
Joshua Goins 2022-05-01 19:44:09 -04:00
parent 2d7024275f
commit f3ad6c0ffa

View file

@ -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,11 +365,12 @@ public class GameScreen implements Screen {
} }
} }
if(closestUnit != null) {
// if we're already next to them, why move? // if we're already next to them, why move?
if (isAdjacent(currentUnit, closestUnit)) { if (isAdjacent(currentUnit, closestUnit)) {
currentlyAwaitingAuxilaryAction = true; currentlyAwaitingAuxilaryAction = true;
} else { } else {
// now that we have the closest unit, let's path to it. // 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()); ArrayList<Vector2> path = AStar.path(new Vector2(currentUnit.positionX, currentUnit.positionY), new Vector2((float) closestUnit.positionX, (float) closestUnit.positionY), getCollision());
if (path != null) { if (path != null) {
Collections.reverse(path); Collections.reverse(path);
@ -382,6 +382,10 @@ public class GameScreen implements Screen {
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();
}
} }
if(currentlyTakingAction) { if(currentlyTakingAction) {
@ -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;