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