Fix SimpleAnimationRunner and RandomAnimationsRunner

This commit is contained in:
2021-03-21 11:14:49 +01:00
parent 83c2bff771
commit 5ac7370d7a
2 changed files with 35 additions and 11 deletions

View File

@@ -28,8 +28,8 @@ public class RandomAnimationsRunner implements AnimationRunner {
private float delay = 0f; private float delay = 0f;
private RealDistribution delayDistribution; private RealDistribution delayDistribution;
private float speed = 0.05f; private float animationSpeed = 0.05f;
private RealDistribution speedDistribution; private RealDistribution animationSpeedDistribution;
private float rotation = 0f; private float rotation = 0f;
private RealDistribution rotationDistribution; private RealDistribution rotationDistribution;
@@ -74,18 +74,18 @@ public class RandomAnimationsRunner implements AnimationRunner {
return this; return this;
} }
public RandomAnimationsRunner speed(float speed) { public RandomAnimationsRunner animationSpeed(float speed) {
this.speed = speed; this.animationSpeed = speed;
return this; return this;
} }
public RandomAnimationsRunner uSpeed(float min, float max) { public RandomAnimationsRunner uAnimationSpeed(float min, float max) {
this.speedDistribution = new UniformRealDistribution(min, max); this.animationSpeedDistribution = new UniformRealDistribution(min, max);
return this; return this;
} }
public RandomAnimationsRunner nSpeed(float mean, float sd) { public RandomAnimationsRunner nAnimationSpeed(float mean, float sd) {
this.speedDistribution = new NormalDistribution(mean, sd); this.animationSpeedDistribution = new NormalDistribution(mean, sd);
return this; return this;
} }
@@ -131,7 +131,7 @@ public class RandomAnimationsRunner implements AnimationRunner {
} }
animation.setScale(scaleDistribution != null ? (float) scaleDistribution.sample() : scale); animation.setScale(scaleDistribution != null ? (float) scaleDistribution.sample() : scale);
animation.setAnimationSpeed(speedDistribution != null ? (float) speedDistribution.sample() : speed); animation.setAnimationSpeed(animationSpeedDistribution != null ? (float) animationSpeedDistribution.sample() : animationSpeed);
animation.setRotation(rotationDistribution != null ? (float) rotationDistribution.sample() : rotation); animation.setRotation(rotationDistribution != null ? (float) rotationDistribution.sample() : rotation);
layer.pushAnimation(new DelayedAnimation(animation, (int) (delayDistribution != null ? delayDistribution.sample() : delay))); layer.pushAnimation(new DelayedAnimation(animation, (int) (delayDistribution != null ? delayDistribution.sample() : delay)));

View File

@@ -2,6 +2,7 @@ package com.bartlomiejpluta.base.api.game.animation;
import com.bartlomiejpluta.base.api.game.context.Context; import com.bartlomiejpluta.base.api.game.context.Context;
import com.bartlomiejpluta.base.api.game.map.layer.base.Layer; import com.bartlomiejpluta.base.api.game.map.layer.base.Layer;
import com.bartlomiejpluta.base.api.util.path.Path;
import org.joml.Vector2fc; import org.joml.Vector2fc;
public class SimpleAnimationRunner implements AnimationRunner { public class SimpleAnimationRunner implements AnimationRunner {
@@ -10,8 +11,13 @@ public class SimpleAnimationRunner implements AnimationRunner {
private Integer repeat = 1; private Integer repeat = 1;
private float scale = 1.0f; private float scale = 1.0f;
private int delay = 0; private int delay = 0;
private float animationSpeed = 0.05f;
private float speed = 0.05f; private float speed = 0.05f;
private float rotation = 0f; private float rotation = 0f;
private Path<Animation> path;
private Integer pathRepeat;
private boolean finishOnPathEnd;
private boolean finishOnPathFail;
public SimpleAnimationRunner(String animationUid) { public SimpleAnimationRunner(String animationUid) {
this.animationUid = animationUid; this.animationUid = animationUid;
@@ -37,8 +43,8 @@ public class SimpleAnimationRunner implements AnimationRunner {
return this; return this;
} }
public SimpleAnimationRunner speed(float speed) { public SimpleAnimationRunner animationSpeed(float speed) {
this.speed = speed; this.animationSpeed = speed;
return this; return this;
} }
@@ -47,10 +53,28 @@ public class SimpleAnimationRunner implements AnimationRunner {
return this; return this;
} }
public SimpleAnimationRunner path(Path<Animation> path, Integer repeat, boolean finishOnEnd, boolean finishOnFail) {
this.path = path;
this.pathRepeat = repeat;
this.finishOnPathEnd = finishOnEnd;
this.finishOnPathFail = finishOnFail;
return this;
}
@Override @Override
public void run(Context context, Layer layer, Vector2fc origin) { public void run(Context context, Layer layer, Vector2fc origin) {
var animation = new DelayedAnimation(context.createAnimation(animationUid), delay); var animation = new DelayedAnimation(context.createAnimation(animationUid), delay);
animation.setPosition(origin); animation.setPosition(origin);
animation.setScale(scale);
animation.setAnimationSpeed(animationSpeed);
animation.setSpeed(speed);
animation.setRotation(rotation);
animation.setRepeat(repeat);
if (path != null) {
animation.followPath(path, pathRepeat, finishOnPathEnd, finishOnPathFail);
}
layer.pushAnimation(animation); layer.pushAnimation(animation);
} }
} }