diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-17 16:01:30 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2018-10-17 16:01:30 +0200 |
commit | a74a9fd597b623a343f23f0384c0edd32bf61603 (patch) | |
tree | c46c46e33db1e5ce7e890b39bf052c00d088f313 /core | |
parent | 661b01f18465a1d23953e1bd87ef3d8579637092 (diff) | |
download | gdx-boardgame-a74a9fd597b623a343f23f0384c0edd32bf61603.zip gdx-boardgame-a74a9fd597b623a343f23f0384c0edd32bf61603.tar.gz |
Piece : add methods needed for futur MoveAnimation
void getPosOn(Tile tile, Orientation orientation, Vector3 v)
void setPosition(float x, float y, float r)
boolean isOn(Tile tile)
boolean isFacing(Orientation orientation)
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/pieces/Piece.java | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/pieces/Piece.java b/core/src/ch/asynk/gdx/boardgame/pieces/Piece.java index e896ea6..31ecca3 100644 --- a/core/src/ch/asynk/gdx/boardgame/pieces/Piece.java +++ b/core/src/ch/asynk/gdx/boardgame/pieces/Piece.java @@ -1,12 +1,17 @@ package ch.asynk.gdx.boardgame.pieces; +import java.lang.Math; + import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.Sprite; +import com.badlogic.gdx.math.Vector3; import ch.asynk.gdx.boardgame.Drawable; +import ch.asynk.gdx.boardgame.Orientation; import ch.asynk.gdx.boardgame.Positionable; import ch.asynk.gdx.boardgame.Rotable; import ch.asynk.gdx.boardgame.Scalable; +import ch.asynk.gdx.boardgame.Tile; public class Piece extends Sprite implements Drawable, Positionable, Rotable, Scalable { @@ -24,4 +29,28 @@ public class Piece extends Sprite implements Drawable, Positionable, Rotable, Sc { setPosition((cx - (getWidth() / 2f)), (cy - (getHeight() / 2f))); } + + public void getPosOn(Tile tile, Orientation orientation, Vector3 v) + { + v.set((tile.x - (getWidth() / 2f)), (tile.y- (getHeight() / 2f)), orientation.r()); + } + + public void setPosition(float x, float y, float r) + { + setPosition(x, y); + setRotation(r); + } + + public boolean isOn(Tile tile) + { + return ( + (Math.abs(getX() - (tile.x - (getWidth() / 2f))) < 3) && + (Math.abs(getY() - (tile.y- (getHeight() / 2f))) < 3) + ); + } + + public boolean isFacing(Orientation orientation) + { + return (Orientation.fromR(getRotation()) == orientation); + } } |