summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/ch/asynk/tankontank/engine/Tile.java10
-rw-r--r--core/src/ch/asynk/tankontank/engine/TileOverlays.java100
2 files changed, 108 insertions, 2 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Tile.java b/core/src/ch/asynk/tankontank/engine/Tile.java
index 4e0589b..66dea74 100644
--- a/core/src/ch/asynk/tankontank/engine/Tile.java
+++ b/core/src/ch/asynk/tankontank/engine/Tile.java
@@ -10,11 +10,17 @@ public interface Tile extends BasicDrawable
public void remove(Pawn pawn);
- public Pawn getTop();
+ public Pawn getTopPawn();
- public int costFrom(Side side);
+ public boolean mustBeDrawn();
+ public boolean occupied();
+ public boolean hasOverlayEnabled();
+
+ public void enableOverlay(int i, boolean enable);
+
+ public List<Tile> adjacents();
public enum Side
{
diff --git a/core/src/ch/asynk/tankontank/engine/TileOverlays.java b/core/src/ch/asynk/tankontank/engine/TileOverlays.java
new file mode 100644
index 0000000..57a95d4
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/engine/TileOverlays.java
@@ -0,0 +1,100 @@
+package ch.asynk.tankontank.engine;
+
+import java.util.List;
+import java.util.ArrayDeque;
+
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+
+import ch.asynk.tankontank.engine.gfx.StackedSpriteNode;
+
+public abstract class TileOverlays implements Tile
+{
+ private StackedSpriteNode overlays;
+ private ArrayDeque<Pawn> stack;
+
+ public TileOverlays(TextureAtlas atlas)
+ {
+ this.stack = null;
+ this.overlays = new StackedSpriteNode(atlas);
+ }
+
+ @Override
+ public int push(Pawn pawn)
+ {
+ if (stack == null) stack = new ArrayDeque<Pawn>();
+ stack.push(pawn);
+ return stack.size();
+ }
+
+ @Override
+ public void remove(Pawn pawn)
+ {
+ stack.remove(pawn);
+ }
+
+ @Override
+ public Pawn getTopPawn()
+ {
+ if ((stack == null) || (stack.size() == 0)) return null;
+ return stack.getFirst();
+ }
+
+ @Override
+ public boolean mustBeDrawn()
+ {
+ if (occupied()) return true;
+ return hasOverlayEnabled();
+ }
+
+ @Override
+ public boolean occupied()
+ {
+ return (stack.size() != 0);
+ }
+
+ @Override
+ public boolean hasOverlayEnabled()
+ {
+ return overlays.isEnabled();
+ }
+
+ @Override
+ public void enableOverlay(int i, boolean enable)
+ {
+ overlays.enable(i, enable);
+ }
+
+ @Override
+ public List<Tile> adjacents()
+ {
+ // FIXME
+ System.err.println("adjacents() Not implemented yet");
+ return null;
+ }
+
+ @Override
+ public void setPosition(float x, float y, float z)
+ {
+ overlays.setPosition(x, y, z);
+ }
+
+ @Override
+ public void draw(Batch batch, float parentAlpha)
+ {
+ overlays.draw(batch, parentAlpha);
+ Pawn pawn = getTopPawn();
+ if (pawn != null)
+ pawn.draw(batch, parentAlpha);
+ }
+
+ @Override
+ public void drawDebug(ShapeRenderer debugShapes)
+ {
+ overlays.drawDebug(debugShapes);
+ Pawn pawn = getTopPawn();
+ if (pawn != null)
+ pawn.drawDebug(debugShapes);
+ }
+}