-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsplash_state.js
More file actions
238 lines (208 loc) · 5.74 KB
/
splash_state.js
File metadata and controls
238 lines (208 loc) · 5.74 KB
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
var splash_state = function (p) {
// object to return
var obj = game_state(p);
// --- private variables ---
//var header_image = p.loadImage("images/screens/header.png");
var back_image = image_manager.get_image("mainscreenbase.png");
var back_color = g.background_color;
// Buttons
// Have a rectangle representing their position and
// a state to go to when pressed
var top_row_y = 150;
var btm_row_y = 420;
var left_x_top = 465;
var left_x_btm = 500;
var incr_x = 40;
var incr_y = 60;
var button_style = {
//height: 160,
rect_color: back_color
};
// Play menu music
sounds.play_menu_music();
var pause_menu_music = function() {
sounds.pause_menu_music();
};
var normal_button = button(p, {
state : function() {
pause_menu_music();
sounds.play_button_click();
return in_game_state(p, obj, 2);
},
rect: {
pos: new p.PVector(left_x_top+2*incr_x, top_row_y),
image: "mnormal.png",
over_image: "mnormal_r.png",
//width: 80,
style: button_style,
}
});
var easy_button = button(p, {
state : function() {
pause_menu_music();
sounds.play_button_click();
return in_game_state(p, obj, 0);
},
rect: {
pos: new p.PVector(left_x_top+incr_x, top_row_y+incr_y),
//text : "Easy",
image: "mbeginner.png",
over_image: "mbeginner_r.png",
//width: 80,
style: button_style,
}
});
var tut_button = button(p, {
state : function() {
pause_menu_music();
sounds.play_button_click();
return in_game_state(p, obj, 1);
},
rect: {
pos: new p.PVector(left_x_top, top_row_y+2*incr_y),
//text : "Tutorial",
image: "mtutorial.png",
over_image: "mtutorial_r.png",
//width: 80,
style: button_style,
}
});
var help_button = button(p, {
state : function() {
sounds.play_button_click();
return help_state(p, obj);
},
rect: {
pos: new p.PVector(left_x_btm, btm_row_y),
image: "mhowtoplay.png",
over_image: "mhowtoplay_r.png",
//width: 100,
style: button_style,
}
});
var scores_button = button(p, {
state : function() {
sounds.play_button_click();
return high_scores_state(p, obj);
},
rect: {
pos: new p.PVector(left_x_btm+incr_x, btm_row_y+incr_y),
image: "mhighscores.png",
over_image: "mhighscores_r.png",
//text: "High Scores",
//width: 100,
style: button_style,
}
});
var options_button = button(p, {
state : function() {
sounds.play_button_click();
return options_state(p, obj);
},
rect: {
pos: new p.PVector(left_x_btm+2*incr_x-10, btm_row_y+2*incr_y),
image: "msettings.png",
over_image: "msettings_r.png",
//width: 120,
style: button_style,
}
});
var credits_button = button(p, {
state : function() {
sounds.play_button_click();
return credits_state(p, obj);
},
rect: {
pos: new p.PVector(p.width-100, 30),
image: "credits.png",
width: 200,
height: 50,
}
});
/*
var splash_style = {
width : 170,
height : 40,
text_color: 0xFFEE0000,
rect_color: back_color,
text_size: 30,
text_align: p.LEFT
};
var button_x = 500;
var button_top = 150;
var button_sep = 60;
var start_button = button(p, {
state : function() { return in_game_state(p, obj); },
rect : {
pos : new p.PVector(button_x, button_top),
style : splash_style,
text : "New Game"
//image : "images/screens/newgame_listcell.png"
}
});
var options_button = button(p, {
state : function() { return options_state(p, obj); },
rect : {
pos : new p.PVector(button_x, button_top+button_sep),
style : splash_style,
text : "Settings"
}
});
var help_button = button(p, {
state : function() { return help_state(p, obj); },
rect : {
pos : new p.PVector(button_x, button_top+2*button_sep),
style : splash_style,
text : "How To Play"
}
});
/*
var high_scores_button = {
state : high_scores_state(),
rectangle : rectangle(p, {
pos : new p.PVector(20, 20),
width : 20,
height : 20
})
};
*/
//Not ordered
var all_buttons = [easy_button, tut_button, normal_button, options_button,
help_button, scores_button, credits_button ];
// --- public methods ---
obj.get_type = function() {
return "splash";
};
obj.update = function() {
//do nothing
};
obj.key_pressed = function(k) {
if (k === 115 || p.keyCode === 13 || k === 32) { //s, enter, space
obj.set_next_state(start_button.get_state());
pause_menu_music();
}
else if (k === 104) { //h
obj.set_next_state(help_button.get_state());
}
};
/*
obj.mouse_moved = function(x, y) {
for_each(
all_buttons,
function(b) {
b.mouse_moved(x, y);
}
);
};
*/
obj.get_all_buttons = function() {
return all_buttons;
};
obj.render = function() {
p.background(back_color);
p.imageMode(p.CENTER);
//p.image(header_image, p.width / 2, 100, p.width * 3/4, 100);
p.image(back_image, p.width/2, p.height/2);
};
return obj;
};