-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUIManager.js
192 lines (127 loc) · 4.4 KB
/
UIManager.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
UIManager = {}
UIManager.init = function(game) {
this.game = game;
this.container = game.add.group();
this.container.fixedToCamera = true;
UIManager.initMainMenu();
UIManager.initGameOverScreen();
UIManager.initGameHUD();
game.input.keyboard.addCallbacks(this, onKeyDown);
}
function onKeyDown(keyEvent) {
if (keyEvent.keyCode == 32) {
//space is down
if (this.mainmenu.visible) {
this.mainmenu_input_handler();
}
else
if (this.gameover.visible && this.goverinstructions.visible) {
this.gameover_input_handler();
}
}
}
UIManager.toTop = function() {
//this.container.parent.add(this.container);
}
UIManager.initGameOverScreen = function() {
var game = this.game;
var gameover = game.add.group();
this.container.add(gameover);
var gog = game.add.graphics(0, 0);
gog.alpha = 0.7;
//gog.beginFill(0xaa2200);
gog.beginFill(0xaa55aa);
gog.drawRect(0, game.world.centerY - 50, game.width, 100);
gog.endFill();
gameover.add(gog);
var gameOverLabel = game.add.bitmapText(game.world.centerX - 140, game.world.centerY - 15, 'carrier_command', "GAME OVER", 16*2);
gameover.add(gameOverLabel);
var instructionsStr = "PRESS [SPACE]";
var instructions = game.add.bitmapText(game.world.centerX - 100, game.world.centerY + 30, 'carrier_command', instructionsStr, 16);
gameover.add(instructions);
gameover.visible = false;
this.goverinstructions = instructions;
this.gameover = gameover;
}
UIManager.initMainMenu = function() {
var game = this.game;
var mainmenu = game.add.group();
this.container.add(mainmenu);
var menug = game.add.graphics(0, 0);
menug.alpha = 0.7;
//menug.beginFill(0xaa2200);
menug.beginFill(0xaa55aa);
menug.drawRect(0, game.world.centerY - 80, game.width, 150);
menug.endFill();
mainmenu.add(menug);
var menuCaption = game.add.bitmapText(game.world.centerX - 320, game.world.centerY - 60, 'carrier_command', "Digicat The Thief", 16*2);
mainmenu.add(menuCaption);
var instructionsStr1 = "MOVE: Left,Right,Down THRUST: Space";
var instructions1 = game.add.bitmapText(game.world.centerX - 330, game.world.centerY, 'carrier_command', instructionsStr1, 16);
mainmenu.add(instructions1);
var instructionsStr2 = "PRESS [SPACE] TO START";
var instructions2 = game.add.bitmapText(game.world.centerX - 200, game.world.centerY + 40, 'carrier_command', instructionsStr2, 16);
mainmenu.add(instructions2);
mainmenu.visible = false;
this.mainmenu = mainmenu;
}
UIManager.initGameHUD = function() {
var game = this.game;
var heart = game.add.sprite(0,0, 'heart');
heart.anchor.setTo(0.5,0.5);
heart.scale.setTo(0.8,0.8);
heart.x = 720;
heart.y = 16;
var livesLabel = game.add.bitmapText(game.world.centerX, game.world.centerY, 'carrier_command', "x"+lives, 16);
livesLabel.x = 740;
livesLabel.y = 8;
livesLabel.stroke = "#000000";
livesLabel.strokeThickness = 10;
var graphics = game.add.graphics(0, 0);
//graphics.beginFill(0xaa2200);
graphics.beginFill(0xaa55aa);
graphics.drawRect(0, 0, game.width, 30);
graphics.endFill();
var levelLabel = game.add.bitmapText(game.world.centerX - 60, 8, 'carrier_command', "LEVEL 1", 16);
levelLabel.tint = 0xffffff;
levelLabel.dirty = true;
this.livesLabel = livesLabel;
this.levelLabel = levelLabel;
this.container.add(graphics);
this.container.add(livesLabel);
this.container.add(levelLabel);
this.container.add(heart);
}
UIManager.hideMainMenu = function() {
this.mainmenu.visible = false;
}
UIManager.showMainMenu = function() {
this.mainmenu.visible = true;
}
UIManager.hideGameOverScreen = function() {
this.gameover.visible = false;
}
UIManager.showGameOverScreen = function() {
this.gameover.visible = true;
this.goverinstructions.visible = false;
this.game.time.events.add(Phaser.Timer.SECOND * 2, function() {
this.goverinstructions.visible = true;
}, this);
}
UIManager.setLevel = function(level) {
this.levelLabel.setText("LEVEL "+level);
}
UIManager.setLives = function(lives) {
this.livesLabel.setText("x"+lives);
}
UIManager.setUIEventHandler = function(eventName, func) {
if (eventName == "gameover_input") {
this.gameover_input_handler = func;
}
else
if (eventName == "mainmenu_input") {
this.mainmenu_input_handler = func;
}
}
UIManager.update = function() {
}