From 015c4c7cb2f1af63bb7015e5200988e3186f6384 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 8 Jun 2020 23:10:37 +0200 Subject: HexScreen : cleanup tiles management --- .../src/ch/asynk/gdx/boardgame/test/HexScreen.java | 29 +++++++++------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java b/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java index cdaa33b..ed87e3c 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/HexScreen.java @@ -223,8 +223,8 @@ public class HexScreen extends AbstractScreen { private class MyBoard { + private final IterableSet losTiles; private final IterableSet moveTiles; - private final IterableSet tilesToDraw; private final Vector2 v; private final Vector3 v3; private final Assets assets; @@ -251,8 +251,8 @@ public class HexScreen extends AbstractScreen this.panzer = new Unit(assets.getTexture(assets.PANZER), true); this.engineer = new Unit(assets.getTexture(assets.ENGINEER), false); this.line = new Sprite(assets.getTexture(assets.LINE)); + this.losTiles = new IterableSet(15); this.moveTiles = new IterableSet(20); - this.tilesToDraw = new IterableSet(15); Tile.defaultOverlay = assets.getAtlas(app.assets.HEX_OVERLAYS); } @@ -262,8 +262,8 @@ public class HexScreen extends AbstractScreen public void draw(SpriteBatch batch) { batch.draw(map, dx, dy, map.getWidth()/2, map.getHeight()/2, map.getWidth(), map.getHeight(), 1, 1, r, 0, 0, map.getWidth(), map.getHeight(), false, false); + for (Tile tile: losTiles) tile.draw(batch); for (Tile tile: moveTiles) tile.draw(batch); - for (Tile tile: tilesToDraw) tile.draw(batch); panzer.draw(batch); engineer.draw(batch); line.draw(batch); @@ -272,14 +272,14 @@ public class HexScreen extends AbstractScreen public void reset() { board.centerOf(0, 0, v); + losTiles.clear(); moveTiles.clear(); - tilesToDraw.clear(); v.set(0, 0); h0 = getHex(0, 0); setUnitOn(panzer, h0.x, h0.y, Orientation.DEFAULT); h1 = getHex(8, 5); setUnitOn(engineer, h1.x, h1.y, Orientation.SW); - updateLine(); + updateUnit(h0, panzer); } private void setUnitOn(Unit unit, int x, int y, Orientation o) @@ -327,13 +327,11 @@ public class HexScreen extends AbstractScreen h0 = hex; else h1 = hex; - updateLine(); - for (Tile tile: moveTiles) tile.enableOverlay(3, false); + for (Tile tile: losTiles) tile.disableOverlays(); + for (Tile tile: moveTiles) tile.disableOverlays(); board.possibleMoves(u, hex, moveTiles); - for (Tile tile: moveTiles) { - tile.enableOverlay(3, true); - tilesToDraw.remove(tile); - } + for (Tile tile: moveTiles) tile.enableOverlay(3, true); + updateLine(); } private void updateLine() @@ -347,14 +345,11 @@ public class HexScreen extends AbstractScreen line.setPosition(x0, y0); line.setSize(d, line.getHeight()); line.setRotation((float) Math.toDegrees(Math.atan2(dy, dx))); - for (Tile tile: tilesToDraw) { - tile.enableOverlay(0, false); - tile.enableOverlay(2, false); - } - board.lineOfSight(h0, h1, tilesToDraw); - for (Tile tile: tilesToDraw) { + board.lineOfSight(h0, h1, losTiles); + for (Tile tile: losTiles) { if (tile.blocked) tile.enableOverlay(0, Orientation.N); else tile.enableOverlay(2, Orientation.N); + moveTiles.remove(tile); } } -- cgit v1.1-2-g2b99