-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.js
30 lines (24 loc) · 971 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
27
28
29
30
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);
game.input.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' or click", style);
text.anchor.setTo(0.5, 0.5);
// If the user already played
if (score > 0) {
// Display its score
var score_label = this.game.add.text(x, y+50, "score: " + score, style);
score_label.anchor.setTo(0.5, 0.5);
}
},
// Start the actual game
start: function() {
this.game.state.start('play');
}
};