From fd7058b8554b2e46a4b56ea824d6fbf48008f4d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Fri, 5 Dec 2014 23:38:54 +0100 Subject: add DestroyAnimation --- .../engine/gfx/animations/DestroyAnimation.java | 62 ++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 core/src/ch/asynk/tankontank/engine/gfx/animations/DestroyAnimation.java diff --git a/core/src/ch/asynk/tankontank/engine/gfx/animations/DestroyAnimation.java b/core/src/ch/asynk/tankontank/engine/gfx/animations/DestroyAnimation.java new file mode 100644 index 0000000..da05d1a --- /dev/null +++ b/core/src/ch/asynk/tankontank/engine/gfx/animations/DestroyAnimation.java @@ -0,0 +1,62 @@ +package ch.asynk.tankontank.engine.gfx.animations; + +import com.badlogic.gdx.utils.Disposable; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.graphics.glutils.ShapeRenderer; + +import ch.asynk.tankontank.engine.gfx.Moveable; +import ch.asynk.tankontank.engine.gfx.Animation; + +public class DestroyAnimation implements Disposable, Animation +{ + private static final float DELAY = 1.5f; + private static final float DURATION = 1.5f; + + private Moveable moveable; + private float x; + private float y; + private int alphaP; + private float elapsed; + + @Override + public void dispose() + { + } + + public void set(float duration, Moveable moveable) + { + this.moveable = moveable; + this.alphaP = 0; + this.elapsed = 0f; + this.x = (moveable.getX() + (moveable.getWidth() / 2f)); + this.y = (moveable.getY() + (moveable.getHeight() / 2f)); + } + + @Override + public boolean animate(float delta) + { + elapsed += delta; + if (elapsed < DELAY) + return false; + + int a = (int) (((elapsed - DELAY) / DURATION) * 10); + if (a != alphaP) { + alphaP = a; + moveable.setAlpha(1f - (alphaP / 10f)); + } + + return (elapsed >= (DELAY + DURATION)); + } + + @Override + public void draw(Batch batch) + { + moveable.draw(batch); + } + + @Override + public void drawDebug(ShapeRenderer debugShapes) + { + moveable.drawDebug(debugShapes); + } +} -- cgit v1.1-2-g2b99