summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2018-10-18 11:05:17 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2018-10-18 11:05:17 +0200
commit02c69db7236f06d1e87055c4af541d051f932bab (patch)
tree1efb6eef73b67e5f4213ef98b184a96e107b297f /core/src/ch/asynk
parent429be1b305dbef415387e9e6a5e56ad8e49fd4c0 (diff)
downloadgdx-boardgame-02c69db7236f06d1e87055c4af541d051f932bab.zip
gdx-boardgame-02c69db7236f06d1e87055c4af541d051f932bab.tar.gz
MoveAnimation : implement onTileChange(Piece, Path) callback
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java20
1 files changed, 18 insertions, 2 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java b/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java
index 27de101..45b355e 100644
--- a/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java
+++ b/core/src/ch/asynk/gdx/boardgame/animations/MoveAnimation.java
@@ -11,6 +11,12 @@ import ch.asynk.gdx.boardgame.Path;
public class MoveAnimation implements Animation, Pool.Poolable
{
+ @FunctionalInterface
+ public interface MoveAnimationCb
+ {
+ void onTileChange(Piece piece, Path path);
+ }
+
private static final Pool<MoveAnimation> moveAnimationPool = new Pool<MoveAnimation>()
{
@Override protected MoveAnimation newObject()
@@ -19,13 +25,14 @@ public class MoveAnimation implements Animation, Pool.Poolable
}
};
- public static MoveAnimation obtain(Piece piece, Path path, float speed)
+ public static MoveAnimation obtain(Piece piece, Path path, float speed, MoveAnimationCb cb)
{
MoveAnimation a = moveAnimationPool.obtain();
a.piece = piece;
a.path = path;
a.speed = speed;
+ a.cb = cb;
a.init();
@@ -34,9 +41,11 @@ public class MoveAnimation implements Animation, Pool.Poolable
private Piece piece;
private Path path;
+ private MoveAnimationCb cb;
private float speed;
private float dp;
private float percent;
+ private boolean notify;
private Vector3 dst = new Vector3();
private Vector3 dt = new Vector3();
@@ -54,7 +63,7 @@ public class MoveAnimation implements Animation, Pool.Poolable
private boolean setNextMove()
{
- boolean done = path.nextVector(piece, dst);
+ boolean done = path.nextPosition(piece, dst);
float dr = (dst.z - piece.getRotation());
if (dr > 180) {
@@ -68,6 +77,7 @@ public class MoveAnimation implements Animation, Pool.Poolable
(dst.y - piece.getY()) * speed,
(dr) * speed
);
+ notify = (dr == 0 ? true : false);
return done;
}
@@ -94,6 +104,12 @@ public class MoveAnimation implements Animation, Pool.Poolable
piece.rotate(dt.z * delta);
percent += (dp * delta);
+ if (notify && percent >= 0.5) {
+ if (cb != null) {
+ cb.onTileChange(piece, path);
+ }
+ notify = false;
+ }
if (percent >= 1f) {
piece.setPosition(dst.x, dst.y, dst.z);
if (!setNextMove()) {