summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-11-20 05:29:45 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2018-11-20 05:29:45 +0100
commit9659eebc4f33493ae4ec9b9464e101927d5c7c71 (patch)
tree004d2694471517bdacb779ea944f4aee10ea124c
parentd525e10316422247c77994735843826cdeea7e90 (diff)
downloadgdx-boardgame-9659eebc4f33493ae4ec9b9464e101927d5c7c71.zip
gdx-boardgame-9659eebc4f33493ae4ec9b9464e101927d5c7c71.tar.gz
Piece : add getShootingPoint() and getImpactPoint()
-rw-r--r--core/src/ch/asynk/gdx/boardgame/Piece.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/Piece.java b/core/src/ch/asynk/gdx/boardgame/Piece.java
index 9e253e4..6b7f2b4 100644
--- a/core/src/ch/asynk/gdx/boardgame/Piece.java
+++ b/core/src/ch/asynk/gdx/boardgame/Piece.java
@@ -5,6 +5,8 @@ import java.lang.Math;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector3;
+import com.badlogic.gdx.math.Vector2;
+import com.badlogic.gdx.math.MathUtils;
import ch.asynk.gdx.boardgame.Drawable;
import ch.asynk.gdx.boardgame.Orientation;
@@ -53,4 +55,23 @@ public class Piece extends Sprite implements Drawable, Positionable, Rotable, Sc
{
return (Orientation.fromR(getRotation()) == orientation);
}
+
+ public void getShootingPoint(Vector2 v, Piece target)
+ {
+ float x0 = getX();
+ float y0 = getY();
+ float x1 = target.getX();
+ float y1 = target.getY();
+
+ float r = (float) (MathUtils.atan2(y1 - y0, x1 - x0));
+ x0 += (Math.cos(r) + 1f) * (getWidth() / 2f);
+ y0 += (Math.sin(r) + 1f) * (getHeight() / 2f);
+
+ v.set(x0, y0);
+ }
+
+ public void getImpactPoint(Vector2 v)
+ {
+ v.set(getX()+ (getWidth() / 2f), getY() + (getHeight() / 2f));
+ }
}