First version of the high score line
This commit is contained in:
parent
c64d9965e3
commit
743282db43
26
src/scene.js
26
src/scene.js
|
@ -4,6 +4,11 @@ class Scene extends Screen {
|
||||||
super(canvas);
|
super(canvas);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.currentHeight = 0;
|
this.currentHeight = 0;
|
||||||
|
|
||||||
|
if (this.maxHeight === undefined) {
|
||||||
|
this.maxHeight = 0;
|
||||||
|
}
|
||||||
|
|
||||||
this.initialize();
|
this.initialize();
|
||||||
|
|
||||||
this.addEventListener('touchstart', (event) => {
|
this.addEventListener('touchstart', (event) => {
|
||||||
|
@ -28,9 +33,8 @@ class Scene extends Screen {
|
||||||
this.currentHeight = 0;
|
this.currentHeight = 0;
|
||||||
this.started = false;
|
this.started = false;
|
||||||
|
|
||||||
if (this.maxHeight === undefined) {
|
// The the line for the high score
|
||||||
this.maxHeigth = 0;
|
this.currentMaxHeight = this.maxHeight;
|
||||||
}
|
|
||||||
|
|
||||||
// Generate random initial platforms
|
// Generate random initial platforms
|
||||||
for (let i = 0.25; i <= 2; i += 0.33) {
|
for (let i = 0.25; i <= 2; i += 0.33) {
|
||||||
|
@ -147,6 +151,8 @@ class Scene extends Screen {
|
||||||
|
|
||||||
this.drawBackground();
|
this.drawBackground();
|
||||||
|
|
||||||
|
this.drawHighScoreLine();
|
||||||
|
|
||||||
for (let platform of this.platforms) {
|
for (let platform of this.platforms) {
|
||||||
this.drawPlatform(platform);
|
this.drawPlatform(platform);
|
||||||
}
|
}
|
||||||
|
@ -158,6 +164,20 @@ class Scene extends Screen {
|
||||||
this.drawHud();
|
this.drawHud();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drawHighScoreLine() {
|
||||||
|
if (this.currentMaxHeight <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let height = this.height() * (1 - this.currentMaxHeight - this.player.size / 2);
|
||||||
|
|
||||||
|
this.context.strokeStyle = 'rgb(255, 255, 255)';
|
||||||
|
this.context.beginPath();
|
||||||
|
this.context.moveTo(0, height);
|
||||||
|
this.context.lineTo(this.width(), height);
|
||||||
|
this.context.stroke();
|
||||||
|
}
|
||||||
|
|
||||||
drawObject(object) {
|
drawObject(object) {
|
||||||
let size = object.size * this.width();
|
let size = object.size * this.width();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue