Add a new spinning effect
This commit is contained in:
parent
bb008d9982
commit
df0741567c
3 changed files with 67 additions and 1 deletions
BIN
android/assets/sound/effect_spin.mp3
Normal file
BIN
android/assets/sound/effect_spin.mp3
Normal file
Binary file not shown.
|
@ -24,6 +24,7 @@ import com.badlogic.gdx.math.Vector2;
|
||||||
|
|
||||||
import io.github.lonamiwebs.klooni.effects.EvaporateEffect;
|
import io.github.lonamiwebs.klooni.effects.EvaporateEffect;
|
||||||
import io.github.lonamiwebs.klooni.effects.IEffect;
|
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.VanishEffect;
|
||||||
import io.github.lonamiwebs.klooni.effects.WaterdropEffect;
|
import io.github.lonamiwebs.klooni.effects.WaterdropEffect;
|
||||||
import io.github.lonamiwebs.klooni.game.Cell;
|
import io.github.lonamiwebs.klooni.game.Cell;
|
||||||
|
@ -70,7 +71,8 @@ public class Effect {
|
||||||
return new Effect[] {
|
return new Effect[] {
|
||||||
new Effect("vanish"),
|
new Effect("vanish"),
|
||||||
new Effect("waterdrop"),
|
new Effect("waterdrop"),
|
||||||
new Effect("evaporate")
|
new Effect("evaporate"),
|
||||||
|
new Effect("spin")
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,6 +94,9 @@ public class Effect {
|
||||||
case 2:
|
case 2:
|
||||||
effect = new EvaporateEffect();
|
effect = new EvaporateEffect();
|
||||||
break;
|
break;
|
||||||
|
case 3:
|
||||||
|
effect = new SpinEffect();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
effect.setInfo(deadCell, culprit);
|
effect.setInfo(deadCell, culprit);
|
||||||
return effect;
|
return effect;
|
||||||
|
@ -104,6 +109,7 @@ public class Effect {
|
||||||
if (name.equals("vanish")) return 0;
|
if (name.equals("vanish")) return 0;
|
||||||
if (name.equals("waterdrop")) return 1;
|
if (name.equals("waterdrop")) return 1;
|
||||||
if (name.equals("evaporate")) return 2;
|
if (name.equals("evaporate")) return 2;
|
||||||
|
if (name.equals("spin")) return 3;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
60
core/src/io/github/lonamiwebs/klooni/effects/SpinEffect.java
Normal file
60
core/src/io/github/lonamiwebs/klooni/effects/SpinEffect.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue