diff --git a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java index a9318ed..4990cc6 100644 --- a/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java +++ b/src/main/java/inf112/fiasko/roborally/gamewrapper/screens/BoardActiveScreen.java @@ -190,18 +190,9 @@ public class BoardActiveScreen extends InteractiveScreen { } roboRallyWrapper.font.getData().setScale(tileDimensions / 44); roboRallyWrapper.font.draw(batch, playerName, viewPortWidth, 2 * tileDimensions * index); - roboRallyWrapper.font.draw(batch, "DMG: " + robot.getDamageTaken() + " LV: " + robot.getAmountOfLives(), - viewPortWidth, 1.5f * tileDimensions + 2 * tileDimensions * (index - 1)); - int lastFlagVisited = robot.getLastFlagVisited(); - if (lastFlagVisited > 0) { - TileType flagType = TileType.getTileTypeFromID(robot.getLastFlagVisited() + 16); - TextureRegion flagRegion = TextureConverterUtil.convertElement(new Tile(flagType, Direction.NORTH)); - batch.draw(flagRegion.getTexture(), viewPortWidth + tileDimensions, 2 * tileDimensions * - (index - 1), tileDimensions / 2, tileDimensions / 2, tileDimensions, - tileDimensions, 1, 1, 0, flagRegion.getRegionX(), - flagRegion.getRegionY(), flagRegion.getRegionWidth(), flagRegion.getRegionWidth(), - false, false); - } + drawDamage(batch, robot, index); + drawLives(batch, robot, index); + drawFlag(batch, robot, index); TextureRegion robotTexture = TextureConverterUtil.convertElement(player.getRobotID()); batch.draw(robotTexture, viewPortWidth, 2 * tileDimensions * (index - 1), tileDimensions, tileDimensions); index++; @@ -209,6 +200,69 @@ public class BoardActiveScreen extends InteractiveScreen { } + /** + * Draws the damage of the player + * @param batch The sprite batch to use for drawing + * @param robot The robot which has visited the flag + * @param index The index of the robot in the robot list + */ + private void drawDamage(SpriteBatch batch, Robot robot, int index) { + int offset = 4 * (tileDimensions / 4); + int tokenSize = tileDimensions / 4; + TextureRegion damageTexture; + for (int i = 0; i < Math.min(robot.getDamageTaken(), 10); i++) { + if (i == 9) { + damageTexture = TextureConverterUtil.getDamageTokenCriticalTexture(); + } else { + damageTexture = TextureConverterUtil.getDamageTokenTexture(); + } + batch.draw(damageTexture.getTexture(), viewPortWidth + offset + ((i % 5) * tokenSize), + tileDimensions + tileDimensions / 4 + 2 * tileDimensions * (index - 1) - + (tokenSize * ((i / 5))), + tileDimensions / 2, + tileDimensions / 2, tokenSize, tokenSize, 1, + 1, 0, damageTexture.getRegionX(), damageTexture.getRegionY(), + damageTexture.getRegionWidth(), damageTexture.getRegionWidth(), false, false); + } + } + + /** + * Draws the lives of the player + * @param batch The sprite batch to use for drawing + * @param robot The robot which has visited the flag + * @param index The index of the robot in the robot list + */ + private void drawLives(SpriteBatch batch, Robot robot, int index) { + TextureRegion lifeTexture = TextureConverterUtil.getLifeTexture(); + int heartSize = tileDimensions / 4; + for (int i = 0; i < robot.getAmountOfLives(); i++) { + batch.draw(lifeTexture.getTexture(), viewPortWidth + heartSize / 2 + i * heartSize, + tileDimensions + 2 * tileDimensions * (index - 1), tileDimensions / 2, + tileDimensions / 2, heartSize, heartSize, 1, + 1, 0, lifeTexture.getRegionX(), lifeTexture.getRegionY(), + lifeTexture.getRegionWidth(), lifeTexture.getRegionWidth(), false, false); + } + } + + /** + * Draws the last flag the player visited + * @param batch The sprite batch to use for drawing + * @param robot The robot which has visited the flag + * @param index The index of the robot in the robot list + */ + private void drawFlag(SpriteBatch batch, Robot robot, int index) { + int lastFlagVisited = robot.getLastFlagVisited(); + if (lastFlagVisited > 0) { + TileType flagType = TileType.getTileTypeFromID(robot.getLastFlagVisited() + 16); + TextureRegion flagRegion = TextureConverterUtil.convertElement(new Tile(flagType, Direction.NORTH)); + batch.draw(flagRegion.getTexture(), viewPortWidth + tileDimensions, 2 * tileDimensions * + (index - 1), tileDimensions / 2, tileDimensions / 2, tileDimensions, + tileDimensions, 1, 1, 0, flagRegion.getRegionX(), + flagRegion.getRegionY(), flagRegion.getRegionWidth(), flagRegion.getRegionWidth(), + false, false); + } + } + /** * Gets the robot with the corresponding robot id * diff --git a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java index 36a96bc..638f20d 100644 --- a/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java +++ b/src/main/java/inf112/fiasko/roborally/networking/RoboRallyClientListener.java @@ -109,13 +109,9 @@ class RoboRallyClientListener extends Listener { e.printStackTrace(); } } - if (newHand.isEmpty()) { - if (wrapper.getGame().getRobotPowerDown()) { - wrapper.getGame().setProgram(new ArrayList<>()); - wrapper.getGame().setGameState(GameState.SKIP_POWER_DOWN_SCREEN); - } else { - wrapper.getGame().setGameState(GameState.CHOOSING_CARDS); - } + if (newHand.isEmpty() && wrapper.getGame().getRobotPowerDown()) { + wrapper.getGame().setProgram(new ArrayList<>()); + wrapper.getGame().setGameState(GameState.SKIP_POWER_DOWN_SCREEN); } else { wrapper.getGame().setGameState(GameState.CHOOSING_CARDS); } diff --git a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java index 7df0458..4429e3c 100644 --- a/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java +++ b/src/main/java/inf112/fiasko/roborally/utility/TextureConverterUtil.java @@ -29,6 +29,7 @@ import java.util.Map; public final class TextureConverterUtil { private static final Texture textureSheet = new Texture(Gdx.files.internal("assets/tiles.png")); private static final Texture robotsTexture = new Texture(Gdx.files.internal("assets/robots.png")); + private static final Texture effectsTexture = new Texture(Gdx.files.internal("assets/effects.png")); private static Map tileSheetTileTextureMappings; private static Map tileSheetTileHasRotatedTextureMappings; private static Map tileSheetParticleTextureMappings; @@ -39,6 +40,30 @@ public final class TextureConverterUtil { private TextureConverterUtil() { } + /** + * Returns the texture to use to display damage tokens + * @return The damage token texture + */ + public static TextureRegion getDamageTokenCriticalTexture() { + return new TextureRegion(effectsTexture, 2 * 64, 0, 64, 64); + } + + /** + * Returns the texture to use to display damage tokens + * @return The damage token texture + */ + public static TextureRegion getDamageTokenTexture() { + return new TextureRegion(effectsTexture, 64, 0, 64, 64); + } + + /** + * Returns the texture to use to display lives + * @return The life texture + */ + public static TextureRegion getLifeTexture() { + return new TextureRegion(effectsTexture, 0, 0, 64, 64); + } + /** * Gets a list of all disposable elements which should be disposed when the software closes * @@ -48,6 +73,7 @@ public final class TextureConverterUtil { List disposables = new ArrayList<>(); disposables.add(textureSheet); disposables.add(robotsTexture); + disposables.add(effectsTexture); return disposables; } diff --git a/src/main/resources/assets/effects.png b/src/main/resources/assets/effects.png new file mode 100644 index 0000000..d16b02c Binary files /dev/null and b/src/main/resources/assets/effects.png differ