diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-06-01 22:24:41 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-06-01 22:24:41 +0200 |
commit | 842d1182857f7dd9ffc7f8bf6252100ae1199c06 (patch) | |
tree | 60b8922ccc405e1ace532f918153feb4baaceff0 | |
parent | 1a9d984f25b07a5c45484825274c177ea39bc1c3 (diff) | |
download | gdx-boardgame-842d1182857f7dd9ffc7f8bf6252100ae1199c06.zip gdx-boardgame-842d1182857f7dd9ffc7f8bf6252100ae1199c06.tar.gz |
Tile : float x,y->cx,cy, add int x,y
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/Orientation.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/Piece.java | 6 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/Tile.java | 14 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java | 38 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java | 2 |
5 files changed, 31 insertions, 31 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/Orientation.java b/core/src/ch/asynk/gdx/boardgame/Orientation.java index 8450dff..2d24603 100644 --- a/core/src/ch/asynk/gdx/boardgame/Orientation.java +++ b/core/src/ch/asynk/gdx/boardgame/Orientation.java @@ -102,6 +102,6 @@ public enum Orientation public static Orientation fromTiles(Tile from, Tile to) { - return fromR(MathUtils.atan2((to.y - from.y), (to.x - from.x)) * MathUtils.radiansToDegrees); + return fromR(MathUtils.atan2((to.cy - from.cy), (to.cx - from.cx)) * MathUtils.radiansToDegrees); } } diff --git a/core/src/ch/asynk/gdx/boardgame/Piece.java b/core/src/ch/asynk/gdx/boardgame/Piece.java index 6d2bf52..b08970c 100644 --- a/core/src/ch/asynk/gdx/boardgame/Piece.java +++ b/core/src/ch/asynk/gdx/boardgame/Piece.java @@ -36,7 +36,7 @@ public class Piece implements Drawable, Positionable, Rotable, Scalable public void getPosOn(Tile tile, Orientation orientation, Vector3 v) { - v.set((tile.x - (getWidth() / 2f)), (tile.y - (getHeight() / 2f)), orientation.r()); + v.set((tile.cx - (getWidth() / 2f)), (tile.cy - (getHeight() / 2f)), orientation.r()); } public void setPosition(float x, float y, float r) @@ -55,8 +55,8 @@ public class Piece implements Drawable, Positionable, Rotable, Scalable public boolean isOn(Tile tile) { return ( - (Math.abs(getX() - (tile.x - (getWidth() / 2f))) < 3) && - (Math.abs(getY() - (tile.y - (getHeight() / 2f))) < 3) + (Math.abs(getX() - (tile.cx - (getWidth() / 2f))) < 3) && + (Math.abs(getY() - (tile.cy - (getHeight() / 2f))) < 3) ); } diff --git a/core/src/ch/asynk/gdx/boardgame/Tile.java b/core/src/ch/asynk/gdx/boardgame/Tile.java index 454f839..504a82d 100644 --- a/core/src/ch/asynk/gdx/boardgame/Tile.java +++ b/core/src/ch/asynk/gdx/boardgame/Tile.java @@ -10,14 +10,18 @@ public class Tile implements Drawable { public static TextureAtlas defaultOverlay = null; - public float x; - public float y; + public int x; + public int y; + public float cx; + public float cy; private Overlays overlays; - public Tile(float x, float y) + public Tile(int x, int y, float cx, float cy) { this.x = x; this.y = y; + this.cx = cx; + this.cy = cy; if (defaultOverlay != null) { setOverlay(defaultOverlay); } @@ -34,7 +38,7 @@ public class Tile implements Drawable public void setOverlay(TextureAtlas textureAtlas) { this.overlays = new Overlays(textureAtlas); - this.overlays.centerOn(x, y); + this.overlays.centerOn(cx, cy); } public void enableOverlay(int i, boolean enable) @@ -54,7 +58,7 @@ public class Tile implements Drawable @Override public String toString() { - return "[" + x + ", " + y + "]"; + return "[" + x + ", " + y + "] => [" + cx + "," + cy + "]"; } @Override public void draw(Batch batch) diff --git a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java index b964668..af6a856 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/AnimationsScreen.java @@ -127,33 +127,29 @@ public class AnimationsScreen extends AbstractScreen private Path buildPath(final GdxBoardTest app) { Tile.defaultOverlay = app.assets.getAtlas(app.assets.HEX_OVERLAYS); - Vector2 v = new Vector2(); Path path = Path.obtain(); path.ensureCapacity(10); - board.centerOf(7, 4, v); - path.add(new Tile(v.x, v.y)); - board.centerOf(6, 4, v); - path.add(new Tile(v.x, v.y)); - board.centerOf(5, 3, v); - path.add(new Tile(v.x, v.y)); - board.centerOf(5, 2, v); - path.add(new Tile(v.x, v.y)); - board.centerOf(6, 2, v); - path.add(new Tile(v.x, v.y)); - board.centerOf(7, 2, v); - path.add(new Tile(v.x, v.y)); - board.centerOf(8, 3, v); - path.add(new Tile(v.x, v.y)); - board.centerOf(9, 4, v); - path.add(new Tile(v.x, v.y)); - board.centerOf(8, 4, v); - path.add(new Tile(v.x, v.y)); - board.centerOf(7, 4, v); - path.add(new Tile(v.x, v.y)); + addTile(path, 7, 4); + addTile(path, 6, 4); + addTile(path, 5, 3); + addTile(path, 5, 2); + addTile(path, 6, 2); + addTile(path, 7, 2); + addTile(path, 8, 3); + addTile(path, 9, 4); + addTile(path, 8, 4); + addTile(path, 7, 4); path.setFinalOrientation(Orientation.NE); return path; } + private void addTile(Path path, int x, int y) + { + final Vector2 v = new Vector2(); + board.centerOf(x, y, v); + path.add(new Tile(x, y, v.x, v.y)); + } + private AnimationBatch getFireAnimationBatch() { AnimationBatch batch = AnimationBatch.obtain(3); diff --git a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java index 8388959..d20e52a 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/BoardScreen.java @@ -150,7 +150,7 @@ public class BoardScreen extends AbstractScreen { final Vector2 v = new Vector2(); board.centerOf(x, y, v); - return new Tile(v.x, v.y); + return new Tile(x, y, v.x, v.y); } public void setHEX_V() |