summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java b/core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java
new file mode 100644
index 0000000..d4f57a8
--- /dev/null
+++ b/core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java
@@ -0,0 +1,66 @@
+package ch.asynk.rustanddust.engine.gfx.animations;
+
+import java.lang.Math;
+
+import com.badlogic.gdx.utils.Pool;
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+
+import ch.asynk.rustanddust.engine.gfx.Moveable;
+
+public class BounceAnimation extends TimedAnimation
+{
+ public static float bounceFactor = 0.3f;
+
+ private Moveable moveable;
+
+ private static final Pool<BounceAnimation> bounceAnimationPool = new Pool<BounceAnimation>() {
+ @Override
+ protected BounceAnimation newObject() {
+ return new BounceAnimation();
+ }
+ };
+
+ public static BounceAnimation get(Moveable moveable, float duration)
+ {
+ BounceAnimation a = bounceAnimationPool.obtain();
+
+ a.moveable = moveable;
+ a.duration = duration;
+
+ return a;
+ }
+
+ @Override
+ public void dispose()
+ {
+ bounceAnimationPool.free(this);
+ }
+
+ @Override
+ protected void begin()
+ {
+ }
+
+ @Override
+ protected void end()
+ {
+ moveable.setScale(1f);
+ }
+
+ @Override
+ protected void update(float percent)
+ {
+ moveable.setScale(1 + bounceFactor * (float) Math.sin(percent * Math.PI));
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ }
+
+ @Override
+ public void drawDebug(ShapeRenderer debugShapes)
+ {
+ }
+}