Show bonus score after clearing strips (closes #7)
This commit is contained in:
parent
1d30887a44
commit
d5f778240d
6 changed files with 32 additions and 12 deletions
|
@ -48,7 +48,7 @@ public abstract class BaseScorer implements BinSerializable {
|
|||
|
||||
//region Private methods
|
||||
|
||||
protected abstract void addScore(int score);
|
||||
protected abstract int addScore(int score);
|
||||
|
||||
// The original game seems to work as follows:
|
||||
// If < 1 were cleared, score = 0
|
||||
|
@ -65,13 +65,13 @@ public abstract class BaseScorer implements BinSerializable {
|
|||
//region Public methods
|
||||
|
||||
// Adds the score a given piece would give
|
||||
public final void addPieceScore(int areaPut) {
|
||||
addScore(areaPut);
|
||||
public final int addPieceScore(int areaPut) {
|
||||
return addScore(areaPut);
|
||||
}
|
||||
|
||||
// Adds the score given by the board, this is, the count of cleared strips
|
||||
public final void addBoardScore(int stripsCleared, int boardSize) {
|
||||
addScore(calculateClearScore(stripsCleared, boardSize));
|
||||
public final int addBoardScore(int stripsCleared, int boardSize) {
|
||||
return addScore(calculateClearScore(stripsCleared, boardSize));
|
||||
}
|
||||
|
||||
public void pause() { }
|
||||
|
|
|
@ -7,21 +7,21 @@ import com.badlogic.gdx.utils.Array;
|
|||
|
||||
import java.util.Iterator;
|
||||
|
||||
class BonusParticleHandler {
|
||||
public class BonusParticleHandler {
|
||||
|
||||
private final Array<BonusParticle> particles;
|
||||
private final Label.LabelStyle labelStyle;
|
||||
|
||||
BonusParticleHandler(final Label.LabelStyle style) {
|
||||
public BonusParticleHandler(final Label.LabelStyle style) {
|
||||
labelStyle = style;
|
||||
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));
|
||||
}
|
||||
|
||||
void run(final Batch batch) {
|
||||
public void run(final Batch batch) {
|
||||
BonusParticle particle;
|
||||
Iterator<BonusParticle> iterator = particles.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
|
|
|
@ -172,6 +172,10 @@ public class PieceHolder implements BinSerializable {
|
|||
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
|
||||
// returns one of the following: NO_DROP, NORMAL_DROP, ON_BOARD_DROP
|
||||
public int dropPiece(Board board) {
|
||||
|
|
|
@ -40,8 +40,9 @@ public class Scorer extends BaseScorer implements BinSerializable {
|
|||
//region Private methods
|
||||
|
||||
@Override
|
||||
protected void addScore(int score) {
|
||||
protected int addScore(int score) {
|
||||
currentScore += score;
|
||||
return score;
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
|
|
@ -58,8 +58,10 @@ public class TimeScorer extends BaseScorer implements BinSerializable {
|
|||
//region Private methods
|
||||
|
||||
@Override
|
||||
protected void addScore(int score) {
|
||||
protected int addScore(int score) {
|
||||
int scoreBefore = getCurrentScore();
|
||||
deadTime += scoreToNanos(score);
|
||||
return getCurrentScore() - scoreBefore;
|
||||
}
|
||||
|
||||
private int nanosToSeconds(long nano) {
|
||||
|
|
|
@ -8,6 +8,8 @@ import com.badlogic.gdx.audio.Sound;
|
|||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
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.DataOutputStream;
|
||||
|
@ -16,6 +18,7 @@ import java.io.IOException;
|
|||
import io.github.lonamiwebs.klooni.Klooni;
|
||||
import io.github.lonamiwebs.klooni.game.BaseScorer;
|
||||
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.Piece;
|
||||
import io.github.lonamiwebs.klooni.game.PieceHolder;
|
||||
|
@ -30,6 +33,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
|||
//region Members
|
||||
|
||||
private final BaseScorer scorer;
|
||||
private final BonusParticleHandler bonusParticleHandler;
|
||||
|
||||
private final Board board;
|
||||
private final PieceHolder holder;
|
||||
|
@ -86,6 +90,10 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
|||
holder = new PieceHolder(layout, HOLDER_PIECE_COUNT, board.cellSize);
|
||||
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"));
|
||||
|
||||
if (gameMode == GAME_MODE_SCORE) {
|
||||
|
@ -165,6 +173,7 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
|||
board.draw(batch);
|
||||
holder.update();
|
||||
holder.draw(batch);
|
||||
bonusParticleHandler.run(batch);
|
||||
|
||||
batch.end();
|
||||
|
||||
|
@ -199,13 +208,17 @@ class GameScreen implements Screen, InputProcessor, BinSerializable {
|
|||
@Override
|
||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||
int area = holder.calculateHeldPieceArea();
|
||||
Vector2 pos = holder.calculateHeldPieceCenter();
|
||||
|
||||
int action = holder.dropPiece(board);
|
||||
if (action == PieceHolder.NO_DROP)
|
||||
return false;
|
||||
|
||||
if (action == PieceHolder.ON_BOARD_DROP) {
|
||||
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
|
||||
if (isGameOver()) {
|
||||
|
|
Loading…
Reference in a new issue