escalator-web/src/menu.js

42 lines
1.3 KiB
JavaScript

const AfterMenu = {
Exit: 0,
Start: 1,
};
function resetHighScoreText() {
return "Reset high score (" + heightToScore(window.localStorage.getItem("maxHeight")) + ")";
}
class Menu extends Gui {
constructor(canvas) {
super(canvas);
this.context.font = "90px Dimbo";
this.context.fillStyle = 'rgb(255, 255, 255)';
this.context.strokeStyle = 'rgb(0, 0, 0)';
this.addButton(new GuiButton(this.context, "Escalator", 0.5, 0.25, Type.StrokeFill));
this.context.font = "30px Dimbo";
this.addButton(new GuiButton(this.context, "New Game", 0.5, 0.55, Type.StrokeFill, () => {
this.status = Status.Finished;
this.after = AfterMenu.Start;
}));
this.addButton(new GuiButton(this.context, resetHighScoreText, 0.5, 0.7, Type.StrokeFill, () => {
window.localStorage.setItem("maxHeight", 0)
}));
this.addButton(new GuiButton(this.context, "Exit", 0.5, 0.85, Type.StrokeFill, () => {
this.status = Status.Finished;
this.after = AfterMenu.Exit;
}));
}
drawBackground() {
this.context.fillStyle = 'rgb(255, 0, 0)';
this.context.beginPath();
this.context.rect(0, 0, this.width(), this.height());
this.context.fill();
}
}