Show current score on time mode (closes #5)
This commit is contained in:
parent
0fb83b69c3
commit
ae3ccf01c1
4 changed files with 32 additions and 13 deletions
|
@ -15,7 +15,7 @@ public abstract class BaseScorer implements BinSerializable {
|
|||
|
||||
//region Members
|
||||
|
||||
final Label leftLabel;
|
||||
final Label currentScoreLabel;
|
||||
final Label highScoreLabel;
|
||||
|
||||
final Texture cupTexture;
|
||||
|
@ -36,8 +36,8 @@ public abstract class BaseScorer implements BinSerializable {
|
|||
Label.LabelStyle labelStyle = new Label.LabelStyle();
|
||||
labelStyle.font = game.skin.getFont("font");
|
||||
|
||||
leftLabel = new Label("0", labelStyle);
|
||||
leftLabel.setAlignment(Align.right);
|
||||
currentScoreLabel = new Label("0", labelStyle);
|
||||
currentScoreLabel.setAlignment(Align.right);
|
||||
|
||||
highScoreLabel = new Label(Integer.toString(highScore), labelStyle);
|
||||
|
||||
|
@ -89,8 +89,8 @@ public abstract class BaseScorer implements BinSerializable {
|
|||
batch.setColor(cupColor);
|
||||
batch.draw(cupTexture, cupArea.x, cupArea.y, cupArea.width, cupArea.height);
|
||||
|
||||
leftLabel.setColor(Klooni.theme.currentScore);
|
||||
leftLabel.draw(batch, 1f);
|
||||
currentScoreLabel.setColor(Klooni.theme.currentScore);
|
||||
currentScoreLabel.draw(batch, 1f);
|
||||
|
||||
highScoreLabel.setColor(Klooni.theme.highScore);
|
||||
highScoreLabel.draw(batch, 1f);
|
||||
|
|
|
@ -3,6 +3,7 @@ package io.github.lonamiwebs.klooni.game;
|
|||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
|
||||
import io.github.lonamiwebs.klooni.actors.Band;
|
||||
import io.github.lonamiwebs.klooni.actors.ThemeCard;
|
||||
|
@ -16,7 +17,7 @@ public class GameLayout {
|
|||
//region Members
|
||||
|
||||
private float screenWidth, marginWidth, availableWidth;
|
||||
private float scoreHeight, boardHeight, pieceHolderHeight, themeCardHeight;
|
||||
private float screenHeight, logoHeight, scoreHeight, boardHeight, pieceHolderHeight, themeCardHeight;
|
||||
|
||||
//endregion
|
||||
|
||||
|
@ -32,14 +33,14 @@ public class GameLayout {
|
|||
|
||||
private void calculate() {
|
||||
screenWidth = Gdx.graphics.getWidth();
|
||||
float screenHeight = Gdx.graphics.getHeight();
|
||||
screenHeight = Gdx.graphics.getHeight();
|
||||
|
||||
// Widths
|
||||
marginWidth = screenWidth * 0.05f;
|
||||
availableWidth = screenWidth - marginWidth * 2f;
|
||||
|
||||
// Heights
|
||||
// logoHeight = screenHeight * 0.10f; // Unused
|
||||
logoHeight = screenHeight * 0.10f;
|
||||
scoreHeight = screenHeight * 0.15f;
|
||||
boardHeight = screenHeight * 0.50f;
|
||||
pieceHolderHeight = screenHeight * 0.25f;
|
||||
|
@ -66,7 +67,7 @@ public class GameLayout {
|
|||
area.x + area.width * 0.5f - cupSize * 0.5f, area.y,
|
||||
cupSize, cupSize);
|
||||
|
||||
scorer.leftLabel.setBounds(
|
||||
scorer.currentScoreLabel.setBounds(
|
||||
area.x, area.y,
|
||||
area.width * 0.5f - cupSize * 0.5f, area.height);
|
||||
|
||||
|
@ -75,6 +76,11 @@ public class GameLayout {
|
|||
area.width * 0.5f - cupSize * 0.5f, area.height);
|
||||
}
|
||||
|
||||
// Special case, we want to position the label on top of the cup
|
||||
void updateTimeLeftLabel(Label timeLeftLabel) {
|
||||
timeLeftLabel.setBounds(0, screenHeight - logoHeight, screenWidth, logoHeight);
|
||||
}
|
||||
|
||||
void update(Board board) {
|
||||
// We can't leave our area, so pick the minimum between available
|
||||
// height and width to determine an appropriated cell size
|
||||
|
|
|
@ -72,7 +72,7 @@ public class Scorer extends BaseScorer implements BinSerializable {
|
|||
int roundShown = MathUtils.round(shownScore);
|
||||
if (roundShown != currentScore) {
|
||||
shownScore = Interpolation.linear.apply(shownScore, currentScore, 0.1f);
|
||||
leftLabel.setText(Integer.toString(MathUtils.round(shownScore)));
|
||||
currentScoreLabel.setText(Integer.toString(MathUtils.round(shownScore)));
|
||||
}
|
||||
super.draw(batch);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package io.github.lonamiwebs.klooni.game;
|
|||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
|
@ -15,6 +17,8 @@ public class TimeScorer extends BaseScorer implements BinSerializable {
|
|||
|
||||
//region Members
|
||||
|
||||
private final Label timeLeftLabel;
|
||||
|
||||
private long startTime;
|
||||
private int highScoreTime;
|
||||
|
||||
|
@ -37,6 +41,12 @@ public class TimeScorer extends BaseScorer implements BinSerializable {
|
|||
super(game, layout, Klooni.getMaxTimeScore());
|
||||
highScoreTime = Klooni.getMaxTimeScore();
|
||||
|
||||
Label.LabelStyle labelStyle = new Label.LabelStyle();
|
||||
labelStyle.font = game.skin.getFont("font");
|
||||
timeLeftLabel = new Label("", labelStyle);
|
||||
timeLeftLabel.setAlignment(Align.center);
|
||||
layout.updateTimeLeftLabel(timeLeftLabel);
|
||||
|
||||
startTime = TimeUtils.nanoTime();
|
||||
deadTime = startTime + START_TIME;
|
||||
|
||||
|
@ -111,10 +121,13 @@ public class TimeScorer extends BaseScorer implements BinSerializable {
|
|||
|
||||
@Override
|
||||
public void draw(SpriteBatch batch) {
|
||||
int timeLeft = pausedTimeLeft < 0 ? getTimeLeft() : pausedTimeLeft;
|
||||
leftLabel.setText(Integer.toString(timeLeft));
|
||||
|
||||
currentScoreLabel.setText(Integer.toString(getCurrentScore()));
|
||||
super.draw(batch);
|
||||
|
||||
int timeLeft = pausedTimeLeft < 0 ? getTimeLeft() : pausedTimeLeft;
|
||||
timeLeftLabel.setText(Integer.toString(timeLeft));
|
||||
timeLeftLabel.setColor(Klooni.theme.currentScore);
|
||||
timeLeftLabel.draw(batch, 1f);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
|
Loading…
Reference in a new issue