Add bonus particle system class
This commit is contained in:
parent
ae3ccf01c1
commit
1d30887a44
2 changed files with 73 additions and 0 deletions
39
core/src/io/github/lonamiwebs/klooni/game/BonusParticle.java
Normal file
39
core/src/io/github/lonamiwebs/klooni/game/BonusParticle.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
package io.github.lonamiwebs.klooni.game;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
|
||||
import io.github.lonamiwebs.klooni.Klooni;
|
||||
|
||||
class BonusParticle {
|
||||
|
||||
private Label label;
|
||||
private float lifetime;
|
||||
|
||||
private final static float SPEED = 1f;
|
||||
|
||||
BonusParticle(final Vector2 pos, final int score, final Label.LabelStyle style) {
|
||||
label = new Label("+"+score, style);
|
||||
label.setBounds(pos.x, pos.y, 0, 0);
|
||||
}
|
||||
|
||||
void run(final Batch batch) {
|
||||
// Update
|
||||
lifetime += SPEED * Gdx.graphics.getDeltaTime();
|
||||
if (lifetime > 1f)
|
||||
lifetime = 1f;
|
||||
|
||||
// Render
|
||||
label.setColor(Klooni.theme.highScore);
|
||||
label.setFontScale(Interpolation.elasticOut.apply(0f, 1f, lifetime));
|
||||
float opacity = Interpolation.linear.apply(1f, 0f, lifetime);
|
||||
label.draw(batch, opacity);
|
||||
}
|
||||
|
||||
boolean done() {
|
||||
return lifetime >= 1f;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package io.github.lonamiwebs.klooni.game;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
class BonusParticleHandler {
|
||||
|
||||
private final Array<BonusParticle> particles;
|
||||
private final Label.LabelStyle labelStyle;
|
||||
|
||||
BonusParticleHandler(final Label.LabelStyle style) {
|
||||
labelStyle = style;
|
||||
particles = new Array<BonusParticle>();
|
||||
}
|
||||
|
||||
void addBonus(final Vector2 pos, final int score) {
|
||||
particles.add(new BonusParticle(pos, score, labelStyle));
|
||||
}
|
||||
|
||||
void run(final Batch batch) {
|
||||
BonusParticle particle;
|
||||
Iterator<BonusParticle> iterator = particles.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
particle = iterator.next();
|
||||
particle.run(batch);
|
||||
if (particle.done())
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue