Showcase all the effects when their shop is shown

This commit is contained in:
Lonami Exo 2017-07-19 16:20:13 +02:00
parent ebc373e26b
commit b0abab11ab
8 changed files with 32 additions and 12 deletions

View file

@ -17,6 +17,7 @@
*/ */
package io.github.lonamiwebs.klooni.actors; package io.github.lonamiwebs.klooni.actors;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; 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.Effect;
import io.github.lonamiwebs.klooni.Klooni; import io.github.lonamiwebs.klooni.Klooni;
import io.github.lonamiwebs.klooni.Theme; 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.Cell;
import io.github.lonamiwebs.klooni.game.GameLayout; 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 // Card-like actor used to display information about a given theme
public class EffectCard extends ShopCard { public class EffectCard extends ShopCard {
@ -33,6 +36,9 @@ public class EffectCard extends ShopCard {
//region Members //region Members
public final Effect effect; public final Effect effect;
private final Cell cell;
private IEffect currentEffect;
private final Texture background; private final Texture background;
private Color color; private Color color;
@ -46,6 +52,7 @@ public class EffectCard extends ShopCard {
color = Klooni.theme.getRandomCellColor(); color = Klooni.theme.getRandomCellColor();
this.effect = effect; this.effect = effect;
cell = Piece.randomCell(0, 0, cellSize);
usedItemUpdated(); usedItemUpdated();
} }
@ -62,7 +69,14 @@ public class EffectCard extends ShopCard {
// Avoid drawing on the borders by adding +1 cell padding +1 to center it // Avoid drawing on the borders by adding +1 cell padding +1 to center it
// so it's becomes cellSize * 2 // 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); super.draw(batch, parentAlpha);
} }

View file

@ -3,7 +3,7 @@ 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.SpriteBatch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
@ -44,7 +44,7 @@ public class EvaporateEffect implements IEffect {
} }
@Override @Override
public void draw(SpriteBatch batch) { public void draw(Batch batch) {
vanishElapsed += Gdx.graphics.getDeltaTime(); vanishElapsed += Gdx.graphics.getDeltaTime();
// Update the size as we fade away // Update the size as we fade away

View file

@ -1,12 +1,12 @@
package io.github.lonamiwebs.klooni.effects; 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 com.badlogic.gdx.math.Vector2;
import io.github.lonamiwebs.klooni.game.Cell; import io.github.lonamiwebs.klooni.game.Cell;
public interface IEffect { public interface IEffect {
void setInfo(Cell deadCell, Vector2 culprit); void setInfo(Cell deadCell, Vector2 culprit);
void draw(SpriteBatch batch); void draw(Batch batch);
boolean isDone(); boolean isDone();
} }

View file

@ -3,7 +3,7 @@ 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.SpriteBatch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.math.Interpolation; import com.badlogic.gdx.math.Interpolation;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
@ -42,7 +42,7 @@ public class VanishEffect implements IEffect {
} }
@Override @Override
public void draw(SpriteBatch batch) { public void draw(Batch batch) {
vanishElapsed += Gdx.graphics.getDeltaTime(); vanishElapsed += Gdx.graphics.getDeltaTime();
// vanishElapsed might be < 0 (delay), so clamp to 0 // vanishElapsed might be < 0 (delay), so clamp to 0

View file

@ -4,7 +4,7 @@ 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.Texture; 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.MathUtils;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
@ -44,7 +44,7 @@ public class WaterdropEffect implements IEffect {
} }
@Override @Override
public void draw(SpriteBatch batch) { public void draw(Batch batch) {
final float dt = Gdx.graphics.getDeltaTime(); final float dt = Gdx.graphics.getDeltaTime();
fallSpeed += fallAcceleration * dt; fallSpeed += fallAcceleration * dt;
pos.y -= fallSpeed * dt; pos.y -= fallSpeed * dt;

View file

@ -27,7 +27,6 @@ import java.io.DataOutputStream;
import java.io.IOException; import java.io.IOException;
import io.github.lonamiwebs.klooni.Effect; import io.github.lonamiwebs.klooni.Effect;
import io.github.lonamiwebs.klooni.Klooni;
import io.github.lonamiwebs.klooni.effects.IEffect; import io.github.lonamiwebs.klooni.effects.IEffect;
import io.github.lonamiwebs.klooni.serializer.BinSerializable; import io.github.lonamiwebs.klooni.serializer.BinSerializable;

View file

@ -20,7 +20,6 @@ package io.github.lonamiwebs.klooni.game;
import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector2;
import java.io.DataInputStream; import java.io.DataInputStream;
@ -62,7 +61,7 @@ public class Cell implements BinSerializable {
colorIndex = ci; colorIndex = ci;
} }
void draw(SpriteBatch batch) { public void draw(Batch batch) {
// Always query the color to the theme, because it might have changed // Always query the color to the theme, because it might have changed
draw(Klooni.theme.getCellColor(colorIndex), batch, pos.x, pos.y, size); draw(Klooni.theme.getCellColor(colorIndex), batch, pos.x, pos.y, size);
} }

View file

@ -112,6 +112,14 @@ public class Piece {
//region Static methods //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 // Generates a random piece with always the same color for the generated shape
static Piece random() { static Piece random() {
// 9 pieces [08]; 4 possible rotations [03] // 9 pieces [08]; 4 possible rotations [03]