diff --git a/android/assets/sound/effect_spin.mp3 b/android/assets/sound/effect_spin.mp3 new file mode 100644 index 0000000..51086c5 Binary files /dev/null and b/android/assets/sound/effect_spin.mp3 differ diff --git a/core/src/io/github/lonamiwebs/klooni/Effect.java b/core/src/io/github/lonamiwebs/klooni/Effect.java index c4b5173..ef6401a 100644 --- a/core/src/io/github/lonamiwebs/klooni/Effect.java +++ b/core/src/io/github/lonamiwebs/klooni/Effect.java @@ -24,6 +24,7 @@ import com.badlogic.gdx.math.Vector2; import io.github.lonamiwebs.klooni.effects.EvaporateEffect; import io.github.lonamiwebs.klooni.effects.IEffect; +import io.github.lonamiwebs.klooni.effects.SpinEffect; import io.github.lonamiwebs.klooni.effects.VanishEffect; import io.github.lonamiwebs.klooni.effects.WaterdropEffect; import io.github.lonamiwebs.klooni.game.Cell; @@ -70,7 +71,8 @@ public class Effect { return new Effect[] { new Effect("vanish"), new Effect("waterdrop"), - new Effect("evaporate") + new Effect("evaporate"), + new Effect("spin") }; } @@ -92,6 +94,9 @@ public class Effect { case 2: effect = new EvaporateEffect(); break; + case 3: + effect = new SpinEffect(); + break; } effect.setInfo(deadCell, culprit); return effect; @@ -104,6 +109,7 @@ public class Effect { if (name.equals("vanish")) return 0; if (name.equals("waterdrop")) return 1; if (name.equals("evaporate")) return 2; + if (name.equals("spin")) return 3; return -1; } diff --git a/core/src/io/github/lonamiwebs/klooni/effects/SpinEffect.java b/core/src/io/github/lonamiwebs/klooni/effects/SpinEffect.java new file mode 100644 index 0000000..8c800a8 --- /dev/null +++ b/core/src/io/github/lonamiwebs/klooni/effects/SpinEffect.java @@ -0,0 +1,60 @@ +package io.github.lonamiwebs.klooni.effects; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.g2d.Batch; +import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.math.Matrix4; +import com.badlogic.gdx.math.Vector2; + +import io.github.lonamiwebs.klooni.game.Cell; + +public class SpinEffect implements IEffect { + private float age; + private Vector2 pos; + private float size; + private Color color; + + private static final float UP_SPEED = 100.0f; + private static final float LIFETIME = 2.0f; + private static final float INV_LIFETIME = 1.0f / LIFETIME; + + private static final float TOTAL_ROTATION = 600; + + @Override + public void setInfo(Cell deadCell, Vector2 culprit) { + age = 0; + pos = deadCell.pos.cpy(); + size = deadCell.size; + color = deadCell.getColorCopy(); + } + + @Override + public void draw(Batch batch) { + age += Gdx.graphics.getDeltaTime(); + + final float progress = age * INV_LIFETIME; + final float currentSize = Interpolation.pow2In.apply(size, 0, progress); + final float currentRotation = Interpolation.sine.apply(0, TOTAL_ROTATION, progress); + + final Matrix4 original = batch.getTransformMatrix().cpy(); + final Matrix4 rotated = batch.getTransformMatrix(); + + final float disp = + + 0.5f * (size - currentSize) // the smaller, the more we need to "push" to center + + currentSize * 0.5f; // center the cell for rotation + + rotated.translate(pos.x + disp, pos.y + disp, 0); + rotated.rotate(0, 0, 1, currentRotation); + rotated.translate(currentSize * -0.5f, currentSize * -0.5f, 0); // revert centering for rotation + + batch.setTransformMatrix(rotated); + Cell.draw(color, batch, 0, 0, currentSize); + batch.setTransformMatrix(original); + } + + @Override + public boolean isDone() { + return age > LIFETIME; + } +}