summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame/Piece.java
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-10-18 16:48:50 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-10-18 16:48:50 +0200
commit3be9db7d4d603791727b2cb3bcec7ae38d3cda50 (patch)
tree4d61605148fd394bb9523b0f8207132769b7ef21 /core/src/ch/asynk/gdx/boardgame/Piece.java
parentab02adb2df8edd794c036547fb61e7f904da780c (diff)
downloadgdx-boardgame-3be9db7d4d603791727b2cb3bcec7ae38d3cda50.zip
gdx-boardgame-3be9db7d4d603791727b2cb3bcec7ae38d3cda50.tar.gz
kill pieces subdirectory for now
Diffstat (limited to 'core/src/ch/asynk/gdx/boardgame/Piece.java')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/Piece.java56
1 files changed, 56 insertions, 0 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/Piece.java b/core/src/ch/asynk/gdx/boardgame/Piece.java
new file mode 100644
index 0000000..9e253e4
--- /dev/null
+++ b/core/src/ch/asynk/gdx/boardgame/Piece.java
@@ -0,0 +1,56 @@
+package ch.asynk.gdx.boardgame;
+
+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
+{
+ public Piece(Texture texture)
+ {
+ super(texture);
+ }
+
+ @Override public float getScale()
+ {
+ return getScaleX();
+ }
+
+ @Override public void centerOn(float cx, float cy)
+ {
+ 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);
+ }
+}