-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathStartMenu.js
112 lines (94 loc) · 2.52 KB
/
StartMenu.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
StartMenu = function(){
this.firstTimeRun = false;
this.timerEnabled = false;
this.inputEnabled = false;
this.cameraFollowsBobby = false;
this.preload = function() {
Level.prototype.preload.call(this);
this.load.spritesheet('menyknapp', 'assets/menyknapp.png');
};
this.create = function() {
Level.prototype.create.call(this);
this.demo = new Demo(this, this.bobby);
this.demo.run();
this.choice = 0;
this.loadChoices();
this.cursors = this.input.keyboard.createCursorKeys();
this.enterKey = game.input.keyboard.addKey(Phaser.Keyboard.ENTER);
this.updateTextColor();
};
this.update = function() {
Level.prototype.update.call(this);
if (this.enterKey.justPressed(1)) {
if (this.choice === 0)
this.play();
}
if (this.cursors.up.justPressed(1)) {
if (this.choice === 0)
this.choice = 2;
else
this.choice--;
this.updateTextColor();
}
else if (this.cursors.down.justPressed(1)) {
this.choice++;
this.choice = this.choice % 3;
this.updateTextColor();
}
};
this.loadChoices = function() {
this.choices = [this.playText, this.loadText, this.highScoreText];
for (var i = 0; i < this.choices.length; i++) {
this.choices[i] = {};
// TODO = Make it so that not every button changes to level 1.
this.choices[i].button = this.add.button(
0, game.height - 310 + i * 100, 'menyknapp', this.play, this
);
// Trust me, this ain't beautiful.
this.choices[i].button.scale.setTo(0.65 + i * i * i * 0.07, 0.65);
var that = this;
this.choices[i].button.onInputOver.add((function(i) {
return function() { that.mouseOver(i); }
})(i), this);
this.choices[i].text = this.add.text(50, game.height - 300 + i*100, "", {
font: "50px Verdana",
fil: "#ffffff",
align: "left"
});
switch (i) {
case 0:
this.choices[i].text.setText("Play");
break;
case 1:
this.choices[i].text.setText("Load");
break;
case 2:
this.choices[i].text.setText("High Score");
break;
}
}
};
this.updateTextColor = function() {
for (var i = 0; i < this.choices.length; i++) {
if (this.choice === i) {
this.choices[i].text.fill = "#ff6789";
} else {
this.choices[i].text.fill = "#ffffff";
}
}
};
/**
* Fired when the play button is pressed.
*/
this.play = function(){
game.state.start('1');
};
/**
* Fired when the active pointer enters a button.
*/
this.mouseOver = function(i){
this.choice = i;
this.updateTextColor();
};
}
StartMenu.prototype = new Level('levels/startMenu.csv', 100, 200, 100, 120);