Show bonus score after clearing strips (closes #7)

This commit is contained in:
Lonami Exo 2017-02-10 18:28:07 +01:00
parent 1d30887a44
commit d5f778240d
6 changed files with 32 additions and 12 deletions

View file

@ -48,7 +48,7 @@ public abstract class BaseScorer implements BinSerializable {
//region Private methods //region Private methods
protected abstract void addScore(int score); protected abstract int addScore(int score);
// The original game seems to work as follows: // The original game seems to work as follows:
// If < 1 were cleared, score = 0 // If < 1 were cleared, score = 0
@ -65,13 +65,13 @@ public abstract class BaseScorer implements BinSerializable {
//region Public methods //region Public methods
// Adds the score a given piece would give // Adds the score a given piece would give
public final void addPieceScore(int areaPut) { public final int addPieceScore(int areaPut) {
addScore(areaPut); return addScore(areaPut);
} }
// Adds the score given by the board, this is, the count of cleared strips // Adds the score given by the board, this is, the count of cleared strips
public final void addBoardScore(int stripsCleared, int boardSize) { public final int addBoardScore(int stripsCleared, int boardSize) {
addScore(calculateClearScore(stripsCleared, boardSize)); return addScore(calculateClearScore(stripsCleared, boardSize));
} }
public void pause() { } public void pause() { }

View file

@ -7,21 +7,21 @@ import com.badlogic.gdx.utils.Array;
import java.util.Iterator; import java.util.Iterator;
class BonusParticleHandler { public class BonusParticleHandler {
private final Array<BonusParticle> particles; private final Array<BonusParticle> particles;
private final Label.LabelStyle labelStyle; private final Label.LabelStyle labelStyle;
BonusParticleHandler(final Label.LabelStyle style) { public BonusParticleHandler(final Label.LabelStyle style) {
labelStyle = style; labelStyle = style;
particles = new Array<BonusParticle>(); particles = new Array<BonusParticle>();
} }
void addBonus(final Vector2 pos, final int score) { public void addBonus(final Vector2 pos, final int score) {
particles.add(new BonusParticle(pos, score, labelStyle)); particles.add(new BonusParticle(pos, score, labelStyle));
} }
void run(final Batch batch) { public void run(final Batch batch) {
BonusParticle particle; BonusParticle particle;
Iterator<BonusParticle> iterator = particles.iterator(); Iterator<BonusParticle> iterator = particles.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {

View file

@ -172,6 +172,10 @@ public class PieceHolder implements BinSerializable {
return heldPiece > -1 ? pieces[heldPiece].calculateArea() : 0; return heldPiece > -1 ? pieces[heldPiece].calculateArea() : 0;
} }
public Vector2 calculateHeldPieceCenter() {
return heldPiece > -1 ? pieces[heldPiece].calculateGravityCenter() : null;
}
// Tries to drop the piece on the given board. As a result, it // Tries to drop the piece on the given board. As a result, it
// returns one of the following: NO_DROP, NORMAL_DROP, ON_BOARD_DROP // returns one of the following: NO_DROP, NORMAL_DROP, ON_BOARD_DROP
public int dropPiece(Board board) { public int dropPiece(Board board) {

View file

@ -40,8 +40,9 @@ public class Scorer extends BaseScorer implements BinSerializable {
//region Private methods //region Private methods
@Override @Override
protected void addScore(int score) { protected int addScore(int score) {
currentScore += score; currentScore += score;
return score;
} }
//endregion //endregion

View file

@ -58,8 +58,10 @@ public class TimeScorer extends BaseScorer implements BinSerializable {
//region Private methods //region Private methods
@Override @Override
protected void addScore(int score) { protected int addScore(int score) {
int scoreBefore = getCurrentScore();
deadTime += scoreToNanos(score); deadTime += scoreToNanos(score);
return getCurrentScore() - scoreBefore;
} }
private int nanosToSeconds(long nano) { private int nanosToSeconds(long nano) {

View file

@ -8,6 +8,8 @@ import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -16,6 +18,7 @@ import java.io.IOException;
import io.github.lonamiwebs.klooni.Klooni; import io.github.lonamiwebs.klooni.Klooni;
import io.github.lonamiwebs.klooni.game.BaseScorer; import io.github.lonamiwebs.klooni.game.BaseScorer;
import io.github.lonamiwebs.klooni.game.Board; import io.github.lonamiwebs.klooni.game.Board;
import io.github.lonamiwebs.klooni.game.BonusParticleHandler;
import io.github.lonamiwebs.klooni.game.GameLayout; import io.github.lonamiwebs.klooni.game.GameLayout;
import io.github.lonamiwebs.klooni.game.Piece; import io.github.lonamiwebs.klooni.game.Piece;
import io.github.lonamiwebs.klooni.game.PieceHolder; import io.github.lonamiwebs.klooni.game.PieceHolder;
@ -30,6 +33,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
//region Members //region Members
private final BaseScorer scorer; private final BaseScorer scorer;
private final BonusParticleHandler bonusParticleHandler;
private final Board board; private final Board board;
private final PieceHolder holder; private final PieceHolder holder;
@ -86,6 +90,10 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
holder = new PieceHolder(layout, HOLDER_PIECE_COUNT, board.cellSize); holder = new PieceHolder(layout, HOLDER_PIECE_COUNT, board.cellSize);
pauseMenu = new PauseMenuStage(layout, game, scorer, gameMode); pauseMenu = new PauseMenuStage(layout, game, scorer, gameMode);
Label.LabelStyle labelStyle = new Label.LabelStyle();
labelStyle.font = game.skin.getFont("font");
bonusParticleHandler = new BonusParticleHandler(labelStyle);
gameOverSound = Gdx.audio.newSound(Gdx.files.internal("sound/game_over.mp3")); gameOverSound = Gdx.audio.newSound(Gdx.files.internal("sound/game_over.mp3"));
if (gameMode == GAME_MODE_SCORE) { if (gameMode == GAME_MODE_SCORE) {
@ -165,6 +173,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
board.draw(batch); board.draw(batch);
holder.update(); holder.update();
holder.draw(batch); holder.draw(batch);
bonusParticleHandler.run(batch);
batch.end(); batch.end();
@ -199,13 +208,17 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
@Override @Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) { public boolean touchUp(int screenX, int screenY, int pointer, int button) {
int area = holder.calculateHeldPieceArea(); int area = holder.calculateHeldPieceArea();
Vector2 pos = holder.calculateHeldPieceCenter();
int action = holder.dropPiece(board); int action = holder.dropPiece(board);
if (action == PieceHolder.NO_DROP) if (action == PieceHolder.NO_DROP)
return false; return false;
if (action == PieceHolder.ON_BOARD_DROP) { if (action == PieceHolder.ON_BOARD_DROP) {
scorer.addPieceScore(area); scorer.addPieceScore(area);
scorer.addBoardScore(board.clearComplete(), board.cellCount); int bonus = scorer.addBoardScore(board.clearComplete(), board.cellCount);
if (bonus > 0)
bonusParticleHandler.addBonus(pos, bonus);
// After the piece was put, check if it's game over // After the piece was put, check if it's game over
if (isGameOver()) { if (isGameOver()) {