diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-12-03 11:16:26 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-12-03 11:16:26 +0100 |
commit | c7ff5337b3a0214084a7eb3d41dcad9a3a5a6d91 (patch) | |
tree | 10ad4b3e442500a0a42d42c390a9694680bd46fc /core | |
parent | e0089b95523fb2e5131e030ee697cde092ad4103 (diff) | |
download | RustAndDust-c7ff5337b3a0214084a7eb3d41dcad9a3a5a6d91.zip RustAndDust-c7ff5337b3a0214084a7eb3d41dcad9a3a5a6d91.tar.gz |
add engine/SelectedTile and plug it into Board
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 11 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/SelectedTile.java | 80 |
2 files changed, 89 insertions, 2 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index c8c5459..40c1736 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -63,6 +63,8 @@ public abstract class Board implements Disposable, Animation private final ArrayList<Animation> nextAnimations = new ArrayList<Animation>(2); private final LinkedHashSet<Tile> tilesToDraw = new LinkedHashSet<Tile>(); + protected SelectedTile selectedTile; + protected Board(int cols, int rows) { // add a frame of OFFMAP Tiles @@ -71,9 +73,9 @@ public abstract class Board implements Disposable, Animation searchBoard = new SearchBoard(this, cols, rows); } - public Board(TileBuilder tileBuilder, Config cfg, Texture texture) + public Board(TileBuilder tileBuilder, Config cfg, Texture boardTexture, SelectedTile selectedTile) { - image = new Image(texture); + image = new Image(boardTexture); this.cfg = cfg; // add a frame of OFFMAP Tiles this.cols = (cfg.cols + 2); @@ -104,6 +106,9 @@ public abstract class Board implements Disposable, Animation sides[3] = Orientation.SOUTH; sides[4] = Orientation.SOUTH_WEST; sides[5] = Orientation.NORTH_WEST; + + this.selectedTile = selectedTile; + animations.add(selectedTile); } @Override @@ -119,6 +124,8 @@ public abstract class Board implements Disposable, Animation for (int i = 0, n = animations.size(); i < n; i++) animations.get(i).dispose(); animations.clear(); + if (selectedTile != null) + selectedTile.dispose(); } public float getWidth() diff --git a/core/src/ch/asynk/tankontank/engine/SelectedTile.java b/core/src/ch/asynk/tankontank/engine/SelectedTile.java new file mode 100644 index 0000000..2c44ac9 --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/SelectedTile.java @@ -0,0 +1,80 @@ +package ch.asynk.tankontank.engine; + +import com.badlogic.gdx.utils.Disposable; + +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +import ch.asynk.tankontank.engine.gfx.Drawable; +import ch.asynk.tankontank.engine.gfx.Animation; +import ch.asynk.tankontank.engine.gfx.animations.Sprites; + +public class SelectedTile implements Disposable, Drawable, Animation +{ + private Sprites sprites; + public Tile tile; + public boolean visible; + public float x; + public float y; + private float elapsed; + private int frame; + private float[] seq; + + public SelectedTile(Texture texture, float[] seq) + { + this.sprites = new Sprites(texture, seq.length, 1); + this.visible = false; + this.tile = null; + this.elapsed = 0f; + this.seq = seq; + } + + public void hide() + { + tile = null; + visible = false; + } + + public void set(Tile tile) + { + this.visible = true; + this.tile = tile; + this.frame = 0; + this.elapsed = 0f; + this.x = (tile.getX() - (sprites.width / 2f)); + this.y = (tile.getY() - (sprites.height / 2f)); + } + + public void dispose() + { + sprites.dispose(); + } + + @Override + public boolean animate(float delta) + { + if (visible) { + elapsed += delta; + if (elapsed > seq[frame]) { + frame = ((frame + 1) % sprites.frames.length); + elapsed = 0f; + } + } + return false; + } + + @Override + public void draw(Batch batch) + { + if (visible) + batch.draw(sprites.frames[frame], x, y); + } + + @Override + public void drawDebug(ShapeRenderer debugShapes) + { + if (visible) + debugShapes.rect(x, y, sprites.width, sprites.height); + } +} |