summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/rustanddust/engine/gfx/animations/BounceAnimation.java
blob: e7de35432ecedfac039787ded51bcb7ee3a28a93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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)
    {
        moveable.draw(batch);
    }

    @Override
    public void drawDebug(ShapeRenderer debugShapes)
    {
    }
}