Draw star after score if new record, fixed some things

This commit is contained in:
Thomas Forgione 2018-08-23 10:49:40 +02:00
parent 83a5ac0f6a
commit 654e4a19b2
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 20 additions and 9 deletions

View File

@ -5,9 +5,9 @@ class Scene extends Screen {
this.player = player; this.player = player;
this.currentHeight = 0; this.currentHeight = 0;
if (this.maxHeight === undefined) { //if (this.maxHeight === undefined) {
this.maxHeight = 0; this.maxHeight = 0;
} //}
this.initialize(); this.initialize();
@ -32,6 +32,7 @@ class Scene extends Screen {
this.cameraSpeed = 0; this.cameraSpeed = 0;
this.currentHeight = 0; this.currentHeight = 0;
this.started = false; this.started = false;
this.newRecord = false;
// The the line for the high score // The the line for the high score
this.currentMaxHeight = this.maxHeight; this.currentMaxHeight = this.maxHeight;
@ -94,9 +95,13 @@ class Scene extends Screen {
// Update high score // Update high score
this.maxHeight = Math.max(this.player.y, this.maxHeight);
this.currentHeight = Math.max(this.player.y, this.currentHeight); this.currentHeight = Math.max(this.player.y, this.currentHeight);
if (this.currentHeight > this.maxHeight) {
this.maxHeight = this.currentHeight;
this.newRecord = true;
}
let previous = { let previous = {
x: this.player.x, x: this.player.x,
y: this.player.y + this.player.size / 2, y: this.player.y + this.player.size / 2,
@ -221,7 +226,11 @@ class Scene extends Screen {
let fontSize = 20; let fontSize = 20;
this.context.font = fontSize + "px Dimbo"; this.context.font = fontSize + "px Dimbo";
this.context.fillStyle = 'rgb(255, 255, 255)'; this.context.fillStyle = 'rgb(255, 255, 255)';
this.context.fillText("Score: " + Math.floor(100 * this.currentHeight), 0, 20); let text = "Score: " + Math.floor(100 * this.currentHeight);
if (this.newRecord) {
text += " ★";
}
this.context.fillText(text, 0, 20);
if (this.status === Status.Running) { if (this.status === Status.Running) {
// Draw pause button // Draw pause button
@ -254,6 +263,7 @@ class Scene extends Screen {
if (this.status === Status.Paused || this.status === Status.Waking) { if (this.status === Status.Paused || this.status === Status.Waking) {
let fontSize = 50; let fontSize = 50;
this.context.fillStyle = 'rgba(255, 255, 255, 0.5)';
this.context.font = fontSize + "px Dimbo"; this.context.font = fontSize + "px Dimbo";
this.context.beginPath(); this.context.beginPath();
@ -264,9 +274,8 @@ class Scene extends Screen {
text = text + ""; text = text + "";
this.context.fillStyle = 'rgb(255, 255, 255)'; this.context.fillStyle = 'rgb(255, 255, 255)';
let size = this.context.measureText(text).width; this.centerFillText(text, this.height() / 2);
this.centerStrokeText(text, this.height() / 2);
this.fillText(text, (this.width() - size) / 2, this.height() / 2 + fontSize);
} }
} }
@ -277,10 +286,11 @@ class Scene extends Screen {
this.context.rect(0, 0, this.width(), this.height()); this.context.rect(0, 0, this.width(), this.height());
this.context.fill(); this.context.fill();
let text = this.newRecord ? "New Record!" : "Game Over";
this.context.fillStyle = 'rgb(255, 255, 255)'; this.context.fillStyle = 'rgb(255, 255, 255)';
this.context.font = "50px Dimbo"; this.context.font = "50px Dimbo";
this.centerFillText('Game Over', this.height() / 4); this.centerFillText(text, this.height() / 4);
this.centerStrokeText('Game Over', this.height() / 4); this.centerStrokeText(text, this.height() / 4);
let size = 40; let size = 40;
this.context.font = size + "px Dimbo"; this.context.font = size + "px Dimbo";
@ -292,6 +302,7 @@ class Scene extends Screen {
let highScoreText = "Highest score: " + this.score(this.maxHeight); let highScoreText = "Highest score: " + this.score(this.maxHeight);
this.centerFillText(highScoreText, this.height() / 2 + 2 * size); this.centerFillText(highScoreText, this.height() / 2 + 2 * size);
this.centerStrokeText(highScoreText, this.height() / 2 + 2 * size); this.centerStrokeText(highScoreText, this.height() / 2 + 2 * size);
} }
makePauseBox() { makePauseBox() {