diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-31 12:05:24 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-31 12:05:24 +0200 |
commit | a0b0ae5396df26c1a65081b093709696a0c0166e (patch) | |
tree | 91d6be1e125b178e53fad3ff18d9f556d259c237 /core/src | |
parent | 0460996fd80f041d2d0e3a0ec1ec98be96bc6af6 (diff) | |
download | gdx-boardgame-a0b0ae5396df26c1a65081b093709696a0c0166e.zip gdx-boardgame-a0b0ae5396df26c1a65081b093709696a0c0166e.tar.gz |
Board/Piece : add dropInPlace(…), dropOnBoard(…)
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/Piece.java | 8 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/boards/Board.java | 8 |
2 files changed, 16 insertions, 0 deletions
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/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); + } } |