Add a new waterdrop effect
This commit is contained in:
parent
d20e3061db
commit
7c9d4c9a99
11 changed files with 136 additions and 5 deletions
|
@ -30,6 +30,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
|||
import io.github.lonamiwebs.klooni.effects.EvaporateEffect;
|
||||
import io.github.lonamiwebs.klooni.effects.IEffect;
|
||||
import io.github.lonamiwebs.klooni.effects.VanishEffect;
|
||||
import io.github.lonamiwebs.klooni.effects.WaterdropEffect;
|
||||
import io.github.lonamiwebs.klooni.game.Cell;
|
||||
import io.github.lonamiwebs.klooni.screens.MainMenuScreen;
|
||||
import io.github.lonamiwebs.klooni.screens.TransitionScreen;
|
||||
|
@ -119,6 +120,8 @@ public class Klooni extends Game {
|
|||
|
||||
// Effects used when clearing a row
|
||||
public static IEffect createEffect(final Cell deadCell, final Vector2 culprit) {
|
||||
// TODO Every effect should probably return a string corresponding to their sound
|
||||
// so there's only one switch around
|
||||
final IEffect effect;
|
||||
switch (usedEffect) {
|
||||
default:
|
||||
|
@ -126,6 +129,9 @@ public class Klooni extends Game {
|
|||
effect = new VanishEffect();
|
||||
break;
|
||||
case 1:
|
||||
effect = new WaterdropEffect();
|
||||
break;
|
||||
case 2:
|
||||
effect = new EvaporateEffect();
|
||||
break;
|
||||
}
|
||||
|
@ -235,6 +241,9 @@ public class Klooni extends Game {
|
|||
effectSound = Gdx.audio.newSound(Gdx.files.internal("sound/effect_vanish.mp3"));
|
||||
break;
|
||||
case 1:
|
||||
effectSound = Gdx.audio.newSound(Gdx.files.internal("sound/effect_waterdrop.mp3"));
|
||||
break;
|
||||
case 2:
|
||||
effectSound = Gdx.audio.newSound(Gdx.files.internal("sound/effect_evaporate.mp3"));
|
||||
break;
|
||||
}
|
||||
|
@ -245,7 +254,8 @@ public class Klooni extends Game {
|
|||
// and when creating instances of a lot of effects it's better if we can
|
||||
// save some processor cycles.
|
||||
if (name.equals("vanish")) return 0;
|
||||
if (name.equals("evaporate")) return 1;
|
||||
if (name.equals("waterdrop")) return 1;
|
||||
if (name.equals("evaporate")) return 2;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package io.github.lonamiwebs.klooni.effects;
|
||||
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.github.lonamiwebs.klooni.SkinLoader;
|
||||
import io.github.lonamiwebs.klooni.game.Cell;
|
||||
|
||||
public class WaterdropEffect implements IEffect {
|
||||
private Vector2 pos;
|
||||
|
||||
private Color cellColor;
|
||||
private Color dropColor;
|
||||
private float cellSize;
|
||||
|
||||
private final float fallAcceleration;
|
||||
private float fallSpeed;
|
||||
|
||||
private static final float FALL_ACCELERATION = 500.0f;
|
||||
private static final float FALL_VARIATION = 50.0f;
|
||||
private static final float COLOR_SPEED = 7.5f;
|
||||
|
||||
private static Texture dropTexture;
|
||||
|
||||
static {
|
||||
dropTexture = SkinLoader.loadPng("cells/drop.png");
|
||||
}
|
||||
|
||||
public WaterdropEffect() {
|
||||
fallAcceleration = FALL_ACCELERATION + MathUtils.random(-FALL_VARIATION, FALL_VARIATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInfo(Cell deadCell, Vector2 culprit) {
|
||||
pos = deadCell.pos.cpy();
|
||||
cellSize = deadCell.size;
|
||||
cellColor = deadCell.getColorCopy();
|
||||
dropColor = new Color(cellColor.r, cellColor.g, cellColor.b, 0.0f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(SpriteBatch batch) {
|
||||
final float dt = Gdx.graphics.getDeltaTime();
|
||||
fallSpeed += fallAcceleration * dt;
|
||||
pos.y -= fallSpeed * dt;
|
||||
|
||||
cellColor.set(
|
||||
cellColor.r, cellColor.g, cellColor.b,
|
||||
Math.max(cellColor.a - COLOR_SPEED * dt, 0.0f)
|
||||
);
|
||||
dropColor.set(
|
||||
cellColor.r, cellColor.g, cellColor.b,
|
||||
Math.min(dropColor.a + COLOR_SPEED * dt, 1.0f)
|
||||
);
|
||||
|
||||
Cell.draw(cellColor, batch, pos.x, pos.y, cellSize);
|
||||
Cell.draw(dropTexture, dropColor, batch, pos.x, pos.y, cellSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDone() {
|
||||
return pos.y + dropTexture.getHeight() < 0;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue