Showcase all the effects when their shop is shown
This commit is contained in:
parent
ebc373e26b
commit
b0abab11ab
8 changed files with 32 additions and 12 deletions
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
package io.github.lonamiwebs.klooni.actors;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
|
@ -24,8 +25,10 @@ import com.badlogic.gdx.graphics.g2d.Batch;
|
|||
import io.github.lonamiwebs.klooni.Effect;
|
||||
import io.github.lonamiwebs.klooni.Klooni;
|
||||
import io.github.lonamiwebs.klooni.Theme;
|
||||
import io.github.lonamiwebs.klooni.effects.IEffect;
|
||||
import io.github.lonamiwebs.klooni.game.Cell;
|
||||
import io.github.lonamiwebs.klooni.game.GameLayout;
|
||||
import io.github.lonamiwebs.klooni.game.Piece;
|
||||
|
||||
// Card-like actor used to display information about a given theme
|
||||
public class EffectCard extends ShopCard {
|
||||
|
@ -33,6 +36,9 @@ public class EffectCard extends ShopCard {
|
|||
//region Members
|
||||
|
||||
public final Effect effect;
|
||||
private final Cell cell;
|
||||
private IEffect currentEffect;
|
||||
|
||||
private final Texture background;
|
||||
private Color color;
|
||||
|
||||
|
@ -46,6 +52,7 @@ public class EffectCard extends ShopCard {
|
|||
color = Klooni.theme.getRandomCellColor();
|
||||
|
||||
this.effect = effect;
|
||||
cell = Piece.randomCell(0, 0, cellSize);
|
||||
usedItemUpdated();
|
||||
}
|
||||
|
||||
|
@ -62,7 +69,14 @@ public class EffectCard extends ShopCard {
|
|||
|
||||
// Avoid drawing on the borders by adding +1 cell padding +1 to center it
|
||||
// so it's becomes cellSize * 2
|
||||
Cell.draw(color, batch, x + cellSize * 2, y + cellSize * 2, cellSize);
|
||||
cell.pos.set(x + cellSize * 2, y + cellSize * 2);
|
||||
|
||||
if (currentEffect != null && !currentEffect.isDone()) {
|
||||
currentEffect.draw(batch);
|
||||
} else {
|
||||
cell.draw(batch);
|
||||
currentEffect = effect.create(cell, cell.pos);
|
||||
}
|
||||
|
||||
super.draw(batch, parentAlpha);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package io.github.lonamiwebs.klooni.effects;
|
|||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
@ -44,7 +44,7 @@ public class EvaporateEffect implements IEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(SpriteBatch batch) {
|
||||
public void draw(Batch batch) {
|
||||
vanishElapsed += Gdx.graphics.getDeltaTime();
|
||||
|
||||
// Update the size as we fade away
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
package io.github.lonamiwebs.klooni.effects;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.github.lonamiwebs.klooni.game.Cell;
|
||||
|
||||
public interface IEffect {
|
||||
void setInfo(Cell deadCell, Vector2 culprit);
|
||||
void draw(SpriteBatch batch);
|
||||
void draw(Batch batch);
|
||||
boolean isDone();
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package io.github.lonamiwebs.klooni.effects;
|
|||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.Interpolation;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class VanishEffect implements IEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(SpriteBatch batch) {
|
||||
public void draw(Batch batch) {
|
||||
vanishElapsed += Gdx.graphics.getDeltaTime();
|
||||
|
||||
// vanishElapsed might be < 0 (delay), so clamp to 0
|
||||
|
|
|
@ -4,7 +4,7 @@ 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.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class WaterdropEffect implements IEffect {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void draw(SpriteBatch batch) {
|
||||
public void draw(Batch batch) {
|
||||
final float dt = Gdx.graphics.getDeltaTime();
|
||||
fallSpeed += fallAcceleration * dt;
|
||||
pos.y -= fallSpeed * dt;
|
||||
|
|
|
@ -27,7 +27,6 @@ import java.io.DataOutputStream;
|
|||
import java.io.IOException;
|
||||
|
||||
import io.github.lonamiwebs.klooni.Effect;
|
||||
import io.github.lonamiwebs.klooni.Klooni;
|
||||
import io.github.lonamiwebs.klooni.effects.IEffect;
|
||||
import io.github.lonamiwebs.klooni.serializer.BinSerializable;
|
||||
|
||||
|
|
|
@ -20,7 +20,6 @@ package io.github.lonamiwebs.klooni.game;
|
|||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Batch;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
|
@ -62,7 +61,7 @@ public class Cell implements BinSerializable {
|
|||
colorIndex = ci;
|
||||
}
|
||||
|
||||
void draw(SpriteBatch batch) {
|
||||
public void draw(Batch batch) {
|
||||
// Always query the color to the theme, because it might have changed
|
||||
draw(Klooni.theme.getCellColor(colorIndex), batch, pos.x, pos.y, size);
|
||||
}
|
||||
|
|
|
@ -112,6 +112,14 @@ public class Piece {
|
|||
|
||||
//region Static methods
|
||||
|
||||
// Only the pieces know how many colors there are, so the method for
|
||||
// creating cells belongs here as a public static one.
|
||||
public static Cell randomCell(final float x, final float y, final float size) {
|
||||
final Cell cell = new Cell(x, y, size);
|
||||
cell.set(MathUtils.random(8));
|
||||
return cell;
|
||||
}
|
||||
|
||||
// Generates a random piece with always the same color for the generated shape
|
||||
static Piece random() {
|
||||
// 9 pieces [0…8]; 4 possible rotations [0…3]
|
||||
|
|
Loading…
Reference in a new issue