summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-02-19 22:21:53 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-02-19 22:21:53 +0100
commitd065bc534df0b906478110f10448cfcc1dbf28df (patch)
tree9c7d5622dd4646cd7f3c27c47336c34c7b7f1fef /core/src/ch/asynk/tankontank
parentcbe4077b975abbceb508c41b33523e1aafac8594 (diff)
downloadRustAndDust-d065bc534df0b906478110f10448cfcc1dbf28df.zip
RustAndDust-d065bc534df0b906478110f10448cfcc1dbf28df.tar.gz
PromoteAnimation: is now a bouncing sin
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/engine/gfx/animations/PromoteAnimation.java38
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java3
2 files changed, 19 insertions, 22 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
index 9694f33..d9f84d9 100644
--- a/core/src/ch/asynk/tankontank/engine/gfx/animations/PromoteAnimation.java
+++ b/core/src/ch/asynk/tankontank/engine/gfx/animations/PromoteAnimation.java
@@ -1,5 +1,7 @@
package ch.asynk.tankontank.engine.gfx.animations;
+import java.lang.Math;
+
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
@@ -14,18 +16,19 @@ public class PromoteAnimation implements Animation, Drawable
private static PromoteAnimation instance = new PromoteAnimation();
private static final float DURATION = 0.3f;
+ private static final float MAX_SCALE = 2f;
private static Sound usSound;
private static Sound geSound;
private static Sound snd;
private static TextureRegion region;
+ private float x0;
+ private float y0;
private float x;
private float y;
- private float x1;
- private float y1;
- private float dx;
- private float dy;
+ private float scale;
+ private float step;
private float volume;
private float elapsed;
@@ -44,20 +47,15 @@ public class PromoteAnimation implements Animation, Drawable
{
}
- public static PromoteAnimation get(boolean us, float x0, float y0, float x1, float y1, float v)
+ public static PromoteAnimation get(boolean us, float x, float y, 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));
+ x = (x - (region.getRegionWidth() / 2.0f));
+ y = (y - (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.x0 = x;
+ instance.y0 = y;
+ instance.scale = 0f;
instance.elapsed = 0f;
snd = (us ? usSound : geSound);
@@ -74,14 +72,14 @@ public class PromoteAnimation implements Animation, Drawable
{
elapsed += delta;
if (elapsed >= DURATION) {
- x = x1;
- y = y1;
snd.play(volume);
return true;
}
- x += (dx * delta);
- y += (dy * delta);
+ float s = MAX_SCALE * (float) Math.sin(Math.PI / DURATION * elapsed);
+ scale = 1f + s;
+ x = x0 - ((region.getRegionWidth() * scale) / 4f);
+ y = y0 - ((region.getRegionHeight() * scale) / 4f);
return false;
}
@@ -89,7 +87,7 @@ public class PromoteAnimation implements Animation, Drawable
@Override
public void draw(Batch batch)
{
- batch.draw(region, x, y);
+ batch.draw(region, x, y, 0, 0, region.getRegionWidth(), region.getRegionHeight(), scale, scale, 0f);
}
@Override
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 7d22dd8..b1213f6 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -311,12 +311,11 @@ public abstract class Map extends Board implements MoveToAnimationCb, ObjectiveS
private int promoteUnit(final Unit unit, final Player player)
{
- // FIXME promoteUnit : ctrl.mapTouch. is not network safe
activatedUnits.add(unit);
Hex hex = unit.getHex();
AnimationSequence seq = AnimationSequence.get(2);
- seq.addAnimation(PromoteAnimation.get((unit.getArmy() == Army.US), ctrl.mapTouch.x, ctrl.mapTouch.y, hex.getX(), hex.getY(), ctrl.cfg.fxVolume));
+ seq.addAnimation(PromoteAnimation.get((unit.getArmy() == Army.US), hex.getX(), hex.getY(), ctrl.cfg.fxVolume));
seq.addAnimation ( RunnableAnimation.get(unit, new Runnable() {
@Override
public void run() {