First version of the high score line

This commit is contained in:
Thomas Forgione 2018-08-22 11:34:36 +02:00
parent c64d9965e3
commit 743282db43
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 23 additions and 3 deletions

View File

@ -4,6 +4,11 @@ class Scene extends Screen {
super(canvas);
this.player = player;
this.currentHeight = 0;
if (this.maxHeight === undefined) {
this.maxHeight = 0;
}
this.initialize();
this.addEventListener('touchstart', (event) => {
@ -28,9 +33,8 @@ class Scene extends Screen {
this.currentHeight = 0;
this.started = false;
if (this.maxHeight === undefined) {
this.maxHeigth = 0;
}
// The the line for the high score
this.currentMaxHeight = this.maxHeight;
// Generate random initial platforms
for (let i = 0.25; i <= 2; i += 0.33) {
@ -147,6 +151,8 @@ class Scene extends Screen {
this.drawBackground();
this.drawHighScoreLine();
for (let platform of this.platforms) {
this.drawPlatform(platform);
}
@ -158,6 +164,20 @@ class Scene extends Screen {
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) {
let size = object.size * this.width();