diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/Camera.java | 8 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/Piece.java | 8 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/Positionable.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/boards/Board.java | 8 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java | 29 |
5 files changed, 38 insertions, 17 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/Camera.java b/core/src/ch/asynk/gdx/boardgame/Camera.java index 5140538..322c6d5 100644 --- a/core/src/ch/asynk/gdx/boardgame/Camera.java +++ b/core/src/ch/asynk/gdx/boardgame/Camera.java @@ -4,6 +4,7 @@ import com.badlogic.gdx.graphics.glutils.HdpiUtils; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Matrix4; @@ -152,7 +153,7 @@ public class Camera extends OrthographicCamera { float deltaX = (dx * zoom * widthFactor); float deltaY = (dy * zoom * heightFactor); - translate(deltaX, -deltaY, 0); + translate(-deltaX, deltaY, 0); clampPosition(); update(true); } @@ -179,6 +180,11 @@ public class Camera extends OrthographicCamera } } + public void unprojectTranslation(int dx, int dy, Vector2 v) + { + v.set((dx * zoom * widthFactor), (-dy * zoom * heightFactor)); + } + public void unproject(int x, int y, Vector3 v) { unproject(v.set(x, y, 0), viewport.x, viewport.y, viewport.width, viewport.height); diff --git a/core/src/ch/asynk/gdx/boardgame/Piece.java b/core/src/ch/asynk/gdx/boardgame/Piece.java index ee0353a..6d2bf52 100644 --- a/core/src/ch/asynk/gdx/boardgame/Piece.java +++ b/core/src/ch/asynk/gdx/boardgame/Piece.java @@ -10,6 +10,7 @@ import com.badlogic.gdx.math.Vector3; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.MathUtils; +import ch.asynk.gdx.boardgame.boards.Board; import ch.asynk.gdx.boardgame.Drawable; import ch.asynk.gdx.boardgame.Orientation; import ch.asynk.gdx.boardgame.Positionable; @@ -44,6 +45,13 @@ public class Piece implements Drawable, Positionable, Rotable, Scalable setRotation(r); } + public void dropOnBoard(Board board, Vector2 v) + { + board.toBoard(getCX(), getCY(), v); + board.centerOf((int)v.x, (int)v.y, v); + centerOn(v.x, v.y); + } + public boolean isOn(Tile tile) { return ( diff --git a/core/src/ch/asynk/gdx/boardgame/Positionable.java b/core/src/ch/asynk/gdx/boardgame/Positionable.java index 53d92f8..36a9cda 100644 --- a/core/src/ch/asynk/gdx/boardgame/Positionable.java +++ b/core/src/ch/asynk/gdx/boardgame/Positionable.java @@ -8,6 +8,8 @@ public interface Positionable public float getHeight(); public void translate(float dx, float dy); public void setPosition(float x, float y); + default public float getCX() { return getX() + (getWidth() / 2f); } + default public float getCY() { return getY() + (getHeight() / 2f); } default public void centerOn(float cx, float cy) { diff --git a/core/src/ch/asynk/gdx/boardgame/boards/Board.java b/core/src/ch/asynk/gdx/boardgame/boards/Board.java index 6cabcee..7c72c25 100644 --- a/core/src/ch/asynk/gdx/boardgame/boards/Board.java +++ b/core/src/ch/asynk/gdx/boardgame/boards/Board.java @@ -2,6 +2,7 @@ package ch.asynk.gdx.boardgame.boards; import com.badlogic.gdx.math.Vector2; +import ch.asynk.gdx.boardgame.Piece; import ch.asynk.gdx.boardgame.Tile; import ch.asynk.gdx.boardgame.tilestorages.TileStorage.TileProvider; import ch.asynk.gdx.boardgame.tilestorages.TileStorage.TileKeyGenerator; @@ -25,4 +26,11 @@ public interface Board extends TileKeyGenerator TCHEBYCHEV } public float distance(int x0, int y0, int x1, int y1, Geometry geometry); + + default public void dropInPlace(Piece piece, Vector2 v) + { + toBoard(piece.getCX(), piece.getCY(), v); + centerOf((int)v.x, (int)v.y, v); + piece.centerOn(v.x, v.y); + } } diff --git a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java index 9b7c4bc..c90d351 100644 --- a/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java +++ b/core/src/ch/asynk/gdx/boardgame/boards/TriangleBoard.java @@ -19,7 +19,6 @@ public class TriangleBoard implements Board private final float m; // h / d private final float h13; // 1/3 height of the triangle private final float h23; // 2/3 height of the triangle - private final float h43; // 4/3 height of the triangle // [0] is 0° facing East // [8] is default @@ -42,12 +41,11 @@ public class TriangleBoard implements Board this.m = this.h / this.d; this.h13 = this.h * 0.33333f; this.h23 = this.h * 0.66666f; - this.h43 = this.h * 1.33333f; this.adjacents = new Tile[3]; } - @Override public int size() { return 0; } // FIXME + @Override public int size() { return cols * rows; } @Override public int[] getAngles() { @@ -60,21 +58,19 @@ public class TriangleBoard implements Board @Override public Tile[] getAdjacents() { return adjacents; } - @Override public void buildAdjacents(int x, int y, TileProvider tileProvider) // FIXME + @Override public void buildAdjacents(int x, int y, TileProvider tileProvider) { + // FIXME } - @Override public int genKey(int x, int y) { return -1; } // FIXME + @Override public int genKey(int x, int y) + { + return (y * cols + x); + } @Override public boolean isOnMap(int x, int y) { - if (this.orientation == BoardFactory.BoardOrientation.VERTICAL) { - if ((y < 0) || (y >= rows)) return false; - if ((x < 0) || (x >= cols)) return false; - } else { - if ((y < 0) || (y >= rows)) return false; - if ((x < -1) || (x >= (cols - 1))) return false; - } + if (x < 0 || x >= cols || y < 0 || y >= rows) return false; return true; } @@ -87,8 +83,8 @@ public class TriangleBoard implements Board cy += (y * this.d); cx += ((x * this.h) + (((x + y) % 2 == 0) ? this.h23 : this.h13)); } else { - cx += (this.d + (x * this.d)); - cy += ((y * this.h) + (((x + y) % 2 == 0) ? this.h13 : this.h23)); + cx += (this.d + ((x -1) * this.d)); + cy += ((y * this.h) + (((x + y) % 2 == 0) ? this.h23 : this.h13)); } v.set(cx, cy); @@ -146,6 +142,7 @@ public class TriangleBoard implements Board col -= 1; } } + col += 1; } v.set(col, row); @@ -160,9 +157,9 @@ public class TriangleBoard implements Board case EUCLIDEAN: return 0; // FIXME case TAXICAB: - return dx + dy; // move should only be allowed through the 3 sides not through de vertices - case TCHEBYCHEV: return dx + dy; + case TCHEBYCHEV: + return (dx > dy ? dx : dy); } return -1; } |