diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-29 02:10:58 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-11-29 02:10:58 +0100 |
commit | 0af95b0519a78e4959c3645b55b2de7a19d27f59 (patch) | |
tree | 506fefad40f06b702f5c5fa2c88f24b11f7357c5 /core/src/ch/asynk | |
parent | fe623df2220f926b1caaee2e3451f5fff9282fb9 (diff) | |
download | RustAndDust-0af95b0519a78e4959c3645b55b2de7a19d27f59.zip RustAndDust-0af95b0519a78e4959c3645b55b2de7a19d27f59.tar.gz |
add PromoteAnimation
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/gfx/animations/PromoteAnimation.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/gfx/animations/PromoteAnimation.java b/core/src/ch/asynk/tankontank/engine/gfx/animations/PromoteAnimation.java new file mode 100644 index 0000000..099946f --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/gfx/animations/PromoteAnimation.java @@ -0,0 +1,97 @@ +package ch.asynk.tankontank.engine.gfx.animations; + +import com.badlogic.gdx.audio.Sound; +import com.badlogic.gdx.graphics.g2d.TextureAtlas; +import com.badlogic.gdx.graphics.g2d.TextureRegion; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +import ch.asynk.tankontank.engine.gfx.Drawable; +import ch.asynk.tankontank.engine.gfx.Animation; + +public class PromoteAnimation implements Animation, Drawable +{ + private static PromoteAnimation instance = new PromoteAnimation(); + + private static final float DURATION = 0.3f; + + private static Sound sound; + private static TextureRegion region; + + private float x; + private float y; + private float x1; + private float y1; + private float dx; + private float dy; + private float volume; + private float elapsed; + + public static void init(TextureAtlas atlas, Sound snd) + { + region = atlas.findRegion("stars"); + sound = snd; + } + + public static void free() + { + sound.dispose(); + } + + protected void PromoteAnimation() + { + } + + public static PromoteAnimation get(float x0, float y0, float x1, float y1, float v) + { + x0 = (x0 - (region.getRegionWidth() / 2.0f)); + y0 = (y0 - (region.getRegionHeight() / 2.0f)); + x1 = (x1 - (region.getRegionWidth() / 2.0f)); + y1 = (y1 - (region.getRegionHeight() / 2.0f)); + + instance.volume = v; + instance.x = x0; + instance.y = y0; + instance.x1 = x1; + instance.y1 = y1; + instance.dx = ((x1 - x0)/ DURATION); + instance.dy = ((y1 - y0) / DURATION); + instance.elapsed = 0f; + + return instance; + } + + @Override + public void dispose() + { + } + + @Override + public boolean animate(float delta) + { + elapsed += delta; + if (elapsed >= DURATION) { + x = x1; + y = y1; + sound.play(volume); + return true; + } + + x += (dx * delta); + y += (dy * delta); + + return false; + } + + @Override + public void draw(Batch batch) + { + batch.draw(region, x, y); + } + + @Override + public void drawDebug(ShapeRenderer debugShapes) + { + debugShapes.rect(x, y, region.getRegionWidth(), region.getRegionHeight()); + } +} |