From a0b0ae5396df26c1a65081b093709696a0c0166e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 31 May 2020 12:05:24 +0200 Subject: =?UTF-8?q?Board/Piece=20:=20add=20dropInPlace(=E2=80=A6),=20dropO?= =?UTF-8?q?nBoard(=E2=80=A6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/src/ch/asynk/gdx/boardgame/Piece.java | 8 ++++++++ core/src/ch/asynk/gdx/boardgame/boards/Board.java | 8 ++++++++ 2 files changed, 16 insertions(+) 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); + } } -- cgit v1.1-2-g2b99