Fix waterdrop and explode particles dying before time
This commit is contained in:
parent
667cdf2472
commit
0c5683c043
2 changed files with 14 additions and 17 deletions
|
@ -3,18 +3,15 @@ package io.github.lonamiwebs.klooni.effects;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.math.Interpolation;
|
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Matrix4;
|
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
import io.github.lonamiwebs.klooni.game.Cell;
|
import io.github.lonamiwebs.klooni.game.Cell;
|
||||||
|
|
||||||
public class ExplodeEffect implements IEffect {
|
public class ExplodeEffect implements IEffect {
|
||||||
private float age;
|
|
||||||
private Vector2 pos;
|
|
||||||
private float size;
|
|
||||||
private Color color;
|
private Color color;
|
||||||
|
boolean dead;
|
||||||
|
|
||||||
private final static float EXPLOSION_X_RANGE = 0.25f;
|
private final static float EXPLOSION_X_RANGE = 0.25f;
|
||||||
private final static float EXPLOSION_Y_RANGE = 0.30f;
|
private final static float EXPLOSION_Y_RANGE = 0.30f;
|
||||||
|
@ -39,17 +36,12 @@ public class ExplodeEffect implements IEffect {
|
||||||
pos.add(vel.x * dt, vel.y * dt);
|
pos.add(vel.x * dt, vel.y * dt);
|
||||||
Cell.draw(color, batch, pos.x, pos.y, size);
|
Cell.draw(color, batch, pos.x, pos.y, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDead() {
|
|
||||||
return pos.y - size < 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Shard[] shards;
|
private Shard[] shards;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setInfo(Cell deadCell, Vector2 culprit) {
|
public void setInfo(Cell deadCell, Vector2 culprit) {
|
||||||
age = 0;
|
|
||||||
color = deadCell.getColorCopy();
|
color = deadCell.getColorCopy();
|
||||||
|
|
||||||
shards = new Shard[MathUtils.random(4, 6)];
|
shards = new Shard[MathUtils.random(4, 6)];
|
||||||
|
@ -59,16 +51,16 @@ public class ExplodeEffect implements IEffect {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw(Batch batch) {
|
public void draw(Batch batch) {
|
||||||
for (int i = 0; i != shards.length; ++i)
|
dead = true; // assume we're death
|
||||||
|
final Vector3 translation = batch.getTransformMatrix().getTranslation(new Vector3());
|
||||||
|
for (int i = shards.length; i-- != 0; ) {
|
||||||
shards[i].draw(batch, Gdx.graphics.getDeltaTime());
|
shards[i].draw(batch, Gdx.graphics.getDeltaTime());
|
||||||
|
dead &= translation.y + shards[i].pos.y + shards[i].size < 0; // all must be dead
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDone() {
|
public boolean isDone() {
|
||||||
for (int i = 0; i != shards.length; ++i)
|
return dead;
|
||||||
if (!shards[i].isDead())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,14 @@ import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||||
import com.badlogic.gdx.math.MathUtils;
|
import com.badlogic.gdx.math.MathUtils;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
import io.github.lonamiwebs.klooni.SkinLoader;
|
import io.github.lonamiwebs.klooni.SkinLoader;
|
||||||
import io.github.lonamiwebs.klooni.game.Cell;
|
import io.github.lonamiwebs.klooni.game.Cell;
|
||||||
|
|
||||||
public class WaterdropEffect implements IEffect {
|
public class WaterdropEffect implements IEffect {
|
||||||
private Vector2 pos;
|
private Vector2 pos;
|
||||||
|
private boolean dead;
|
||||||
|
|
||||||
private Color cellColor;
|
private Color cellColor;
|
||||||
private Color dropColor;
|
private Color dropColor;
|
||||||
|
@ -60,10 +62,13 @@ public class WaterdropEffect implements IEffect {
|
||||||
|
|
||||||
Cell.draw(cellColor, batch, pos.x, pos.y, cellSize);
|
Cell.draw(cellColor, batch, pos.x, pos.y, cellSize);
|
||||||
Cell.draw(dropTexture, dropColor, batch, pos.x, pos.y, cellSize);
|
Cell.draw(dropTexture, dropColor, batch, pos.x, pos.y, cellSize);
|
||||||
|
|
||||||
|
final Vector3 translation = batch.getTransformMatrix().getTranslation(new Vector3());
|
||||||
|
dead = translation.y + pos.y + dropTexture.getHeight() < 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDone() {
|
public boolean isDone() {
|
||||||
return pos.y + dropTexture.getHeight() < 0;
|
return dead;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue