escalator-web/src/menu.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-08-23 11:50:05 +02:00
function resetHighScoreText() {
return "High score: " + heightToScore(window.localStorage.getItem("maxHeight"));
}
function collectableText() {
return "Coins: " + window.localStorage.getItem("collectableNumber");
2018-08-23 11:50:05 +02:00
}
class Menu extends Gui {
2018-08-21 15:58:08 +02:00
constructor(canvas) {
super(canvas);
2018-08-23 11:50:05 +02:00
this.context.font = "90px Dimbo";
2018-08-21 15:58:08 +02:00
this.context.fillStyle = 'rgb(255, 255, 255)';
2018-08-23 11:50:05 +02:00
this.context.strokeStyle = 'rgb(0, 0, 0)';
this.addButton(new GuiButton(this.context, "Escalator", 0.5, 0.25, Type.StrokeFill));
2018-08-21 15:58:08 +02:00
2018-08-22 16:18:37 +02:00
this.context.font = "30px Dimbo";
this.addButton(new GuiButton(this.context, "New Game", 0.5, 0.5, Type.StrokeFill, () => {
2018-08-23 11:50:05 +02:00
this.status = Status.Finished;
this.after = Screens.Game;
2018-08-23 11:50:05 +02:00
}));
2018-08-21 15:58:08 +02:00
this.addButton(new GuiButton(this.context, resetHighScoreText, 0.5, 0.6, Type.StrokeFill));
this.addButton(new GuiButton(this.context, collectableText, 0.5, 0.7, Type.StrokeFill));
2018-08-21 15:58:08 +02:00
this.addButton(new GuiButton(this.context, "Exit", 0.5, 0.8, Type.StrokeFill, () => {
2018-08-23 11:50:05 +02:00
this.status = Status.Finished;
this.after = Screens.Exit;
2018-08-23 11:50:05 +02:00
}));
2018-08-21 15:58:08 +02:00
}
drawBackground() {
this.context.fillStyle = 'rgb(255, 0, 0)';
this.context.beginPath();
this.context.rect(0, 0, this.width(), this.height());
this.context.fill();
}
}