diff options
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Board.java | 47 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Pawn.java | 24 |
2 files changed, 40 insertions, 31 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java index 1f5ff0a..694161b 100644 --- a/core/src/ch/asynk/tankontank/engine/Board.java +++ b/core/src/ch/asynk/tankontank/engine/Board.java @@ -27,6 +27,7 @@ import ch.asynk.tankontank.engine.gfx.animations.RunnableAnimation; public abstract class Board implements Disposable { + private GridPoint2 tmpPt = new GridPoint2(); private final Tile neighbours[] = new Tile[6]; protected List<ArrayList<SearchBoard.Node>> paths; @@ -301,7 +302,8 @@ public abstract class Board implements Disposable GridPoint2 to = gridPoint2Pool.obtain(); while (units.hasNext()) { Pawn target = units.next(); - getHexUnder(target, to); + Tile tile = target.getTile(); + to.set(tile.getCol(), tile.getRow()); if (searchBoard.buildAttack(pawn, true, target, coords.x, coords.y, to.x, to.y)) { targets.add(to); to = gridPoint2Pool.obtain(); @@ -342,7 +344,8 @@ public abstract class Board implements Disposable while (units.hasNext()) { Pawn p = units.next(); if ((p == pawn) || !p.canAttack()) continue; - getHexUnder(p, from); + Tile tile = p.getTile(); + from.set(tile.getCol(), tile.getRow()); if (searchBoard.buildAttack(p, !p.canAssistAttackWithoutLos(), target, from.x, from.y, coords.x, coords.y)) { if (p != pawn) { assists.add(from); @@ -499,43 +502,43 @@ public abstract class Board implements Disposable return getTile(coords.x, coords.y).getTopPawn(); } - private int pushPawnAt(Pawn pawn, GridPoint2 coords) + private int pushPawnOnto(Pawn pawn, Tile tile) { - Tile tile = getTile(coords.x, coords.y); tilesToDraw.add(tile); return tile.push(pawn); } public int removePawn(Pawn pawn) { - return removePawnFrom(pawn, getHexUnder(pawn)); - } - - public int removePawnFrom(Pawn pawn, GridPoint2 coords) - { - Tile tile = getTile(coords.x, coords.y); + Tile tile = pawn.getTile(); int n = tile.remove(pawn); if (!tile.mustBeDrawn()) tilesToDraw.remove(tile); return n; } - public Pawn setPawnAt(Pawn pawn, GridPoint2 coords, Orientation o) + public Pawn setPawnOnto(Pawn pawn, Tile tile, Orientation o) + { + return setPawnOnto(pawn, tile, o.r()); + } + + public Pawn setPawnOnto(Pawn pawn, Tile tile, float r) { - pawn.setOnTile(getTile(coords.x, coords.y), o); - pushPawnAt(pawn, coords); + pawn.setOnTile(tile, r); + pushPawnOnto(pawn, tile); return pawn; } protected void movePawn(final Pawn pawn, int cost, ArrayList<Vector3> path, RunnableAnimation whenDone) { - removePawnFrom(pawn, getHexUnder(pawn)); + removePawn(pawn); AnimationSequence seq = pawn.getMoveAnimation(path); seq.addAnimation(RunnableAnimation.get(pawn, new Runnable() { @Override public void run() { - pushPawnAt(pawn, getHexUnder(pawn)); + getHexAt(pawn.getCenter(), tmpPt); + setPawnOnto(pawn, getTile(tmpPt.x, tmpPt.y), pawn.getRotation()); } })); seq.addAnimation(whenDone); @@ -557,13 +560,13 @@ public abstract class Board implements Disposable protected void revertLastPawnMove(final Pawn pawn, RunnableAnimation whenDone) { - removePawnFrom(pawn, getHexUnder(pawn)); + removePawn(pawn); AnimationSequence seq = pawn.getRevertLastMoveAnimation(); seq.addAnimation(RunnableAnimation.get(pawn, new Runnable() { @Override public void run() { - pushPawnAt(pawn, getHexUnder(pawn)); + pushPawnOnto(pawn, pawn.getTile()); } })); seq.addAnimation(whenDone); @@ -571,16 +574,6 @@ public abstract class Board implements Disposable pawn.revertLastMove(); } - public GridPoint2 getHexUnder(Pawn pawn) - { - return getHexAt(pawn.getCenter(), null); - } - - public GridPoint2 getHexUnder(Pawn pawn, GridPoint2 hex) - { - return getHexAt(pawn.getCenter(), hex); - } - public GridPoint2 getHexAt(Vector2 v, GridPoint2 hex) { return getHexAt(hex, v.x, v.y); diff --git a/core/src/ch/asynk/tankontank/engine/Pawn.java b/core/src/ch/asynk/tankontank/engine/Pawn.java index 3d414ef..a433796 100644 --- a/core/src/ch/asynk/tankontank/engine/Pawn.java +++ b/core/src/ch/asynk/tankontank/engine/Pawn.java @@ -36,8 +36,10 @@ public abstract class Pawn implements Moveable, Disposable private static final float MOVE_TIME = 0.4f; - private Vector3 position = new Vector3(0f, 0f, 0f); - private Vector3 prevPosition = new Vector3(0f, 0f, 0f); + private Vector3 position; + private Vector3 prevPosition; + private Tile tile; + private Tile prevTile; protected Faction faction; protected String descr; private Image image; @@ -71,10 +73,15 @@ public abstract class Pawn implements Moveable, Disposable protected Pawn() { + this.tile = null; + this.prevTile = null; + this.position = new Vector3(0f, 0f, 0f); + this.prevPosition = new Vector3(0f, 0f, 0f); } public Pawn(Faction faction, TextureAtlas atlas, String name) { + this(); this.faction = faction; this.descr = descr; this.image = new Image(atlas.findRegion(name)); @@ -108,6 +115,11 @@ public abstract class Pawn implements Moveable, Disposable return (attack.isClear && attack.isFlank); } + public Tile getTile() + { + return tile; + } + public Vector3 getPosition() { return position; @@ -120,6 +132,8 @@ public abstract class Pawn implements Moveable, Disposable private void revertPosition() { + this.tile = this.prevTile; + this.prevTile = null; position.set(prevPosition); prevPosition.set(0f, 0f, 0f); setPosition(position.x, position.y, position.z); @@ -143,11 +157,13 @@ public abstract class Pawn implements Moveable, Disposable return pos; } - public void setOnTile(Tile tile, Orientation o) + public void setOnTile(Tile tile, float z) { + this.prevTile = this.tile; + this.tile = tile; float x = (tile.getX() - (image.getWidth() / 2f)); float y = (tile.getY() - (image.getHeight() / 2f)); - setPosition(x, y, o.r()); + setPosition(x, y, z); } @Override |