-
Notifications
You must be signed in to change notification settings - Fork 1
/
menu.js
26 lines (22 loc) · 932 Bytes
/
menu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var menu_state = {
create: function() {
// Call the 'start' function when pressing the spacebar
var space_key = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);
space_key.onDown.add(this.start, this);
// Defining variables
var style = { font: "30px Arial", fill: "#ffffff" };
var x = game.world.width/2, y = game.world.height/2;
// Adding a text centered on the screen
var text = this.game.add.text(x, y-50, "Press space to start", style);
text.anchor.setTo(0.5, 0.5);
if (localStorage.getItem("highscore") > 0) {
// Display its score
var score_label = this.game.add.text(x, y+50, "Highscore: " + localStorage.getItem("highscore"), style);
score_label.anchor.setTo(0.5, 0.5);
}
},
// Start the actual game
start: function() {
this.game.state.start('main');
}
};