From f3ad6c0ffa4c85e5187d8aae247029360090709f Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sun, 1 May 2022 19:44:09 -0400 Subject: [PATCH] Add some null checks, and fix typos in comments --- .../watersymbol/screens/GameScreen.java | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/core/src/com/redstrate/watersymbol/screens/GameScreen.java b/core/src/com/redstrate/watersymbol/screens/GameScreen.java index dc3359a..6c34843 100644 --- a/core/src/com/redstrate/watersymbol/screens/GameScreen.java +++ b/core/src/com/redstrate/watersymbol/screens/GameScreen.java @@ -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 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 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 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 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;