-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathoptions_state.js
More file actions
209 lines (184 loc) · 5.37 KB
/
options_state.js
File metadata and controls
209 lines (184 loc) · 5.37 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
var options_state = function (p, prev_state) {
// object to return
var obj = game_state(p);
obj.set_previous_state(prev_state);
// Used to determine whether to play menu music when 'music' button is toggled
var prev_was_splash = false;
if (prev_state.get_type() === "splash") {
prev_was_splash = true;
}
// --- private variables ---
var background_image = image_manager.get_image("settingssplash.png");
var button_style = {
text_x_offset : 60,
text_y_offset: -3,
text_align: p.LEFT
};
// Buttons
var col1_x = p.width/2 - 120;
var col2_x = p.width/2 + 120;
var back_button = button(p, {
state : function() {
sounds.play_button_back();
return prev_state;
},
rect : {
pos : new p.PVector(p.width / 2, p.height - 80),
//width : 120,
//height : 50,
//text: "Back",
//text_x_offset: 5,
//text_y_offset: -8,
image: "back.png",
}
});
// Options
//var option_image = "bullet_listcell.png";
var sound_fx_button = option_button(p, {
click_fun : function() {sounds.play_button_click(); g.toggle_sound_fx();},
global_var : "sound_fx",
rect : {
pos : new p.PVector(col1_x, p.height/2 - 70),
//text: "Sound Effects",
//text_x_offset: 60,
image : "set_sound.png",//option_image,
//over_image : "set_sound_a.png",
//style: button_style
}
});
var music_button = option_button(p, {
click_fun : function() {
sounds.play_button_click();
// toggle the flag
g.toggle_music();
if (g.music) {
if (prev_was_splash) {
sounds.play_menu_music();
}
}
else {
sounds.pause_menu_music();
}
},
global_var : "music",
rect : {
pos : new p.PVector(col1_x, p.height/2 + 40),
//text: "Music",
//text_x_offset: 60,
image : "set_music.png",//option_image,
//over_image : "set_music_a.png",
//style: button_style
}
});
var spacebar_button = option_button(p, {
click_fun : function() {
sounds.play_button_click();
g.toggle_spacebar_to_fire();
},
global_var : "spacebar_to_fire",
rect : {
pos : new p.PVector(col2_x, p.height/2 - 70),
//text: "Spacebar to Fire",
//text_x_offset : 60,
image : "set_spacebar.png",//option_image,
//over_image : "set_spacebar_a.png",
//style: button_style
}
});
var mouse_button = option_button(p, {
click_fun : function() {
sounds.play_button_click();
g.toggle_click_to_fire();
},
global_var : "click_to_fire",
rect : {
pos : new p.PVector(col2_x, p.height/2 + 40),
//text: "Mouse Click to Fire",
//text_x_offset : 60,
image : "set_click.png",//option_image,
//over_image : "set_click_a.png",
//style: button_style
}
});
var mouse_to_select_button = option_button(p, {
click_fun : function() {
sounds.play_button_click();
g.toggle_mouse_to_select();
},
global_var : "mouse_to_select",
rect : {
pos : new p.PVector(col2_x, p.height/2 + 140),
//text: "Mouse to Select Cells\nInstead of Left/Right",
image : "set_mouseselect.png",//option_image,
//over_image : "set_mouseselect_a.png",
//text_x_offset : 60,
//style: button_style
}
});
var track_left_button = button(p, {
state : function() {
sounds.play_button_click();
g.prev_track();
return obj;
},
rect : {
pos : new p.PVector(col1_x - 50, p.height/2 + 145),
image : "track_left.png",
}
});
var track_right_button = button(p, {
state : function() {
sounds.play_button_click();
g.next_track();
return obj;
},
rect : {
pos : new p.PVector(col1_x + 50, p.height/2 + 145),
image : "track_right.png",
}
});
//Not ordered
var all_option_buttons = [sound_fx_button, music_button,
spacebar_button, mouse_button, mouse_to_select_button];
var all_buttons = [back_button, track_left_button, track_right_button]
.concat(all_option_buttons);
// --- public methods ---
obj.get_type = function() {
return "options";
};
obj.update = function() {
//do nothing
};
obj.key_pressed = function(k) {
if (k === 115 || p.keyCode === 13 || k === 32) { //s, enter, space
}
else if (k === 104) { //h
}
};
obj.get_all_buttons = function() {
return all_buttons;
};
obj.render = function() {
//p.background(g.background_color);
//p.fill(g.background_color);
//p.rect(100, 100, 500, 500);
p.imageMode(p.CORNERS);
p.image(background_image, 0, 0);//, p.width, p.height);
// draw the track button background manually
var track_x = col1_x;
var track_y = p.height/2 + 140;
var track_image = image_manager.get_image("set_track.png");
p.imageMode(p.CENTER);
p.image(track_image, track_x, track_y);
// draw current track
p.fill(0);
p.textAlign(p.CENTER);
p.textSize(14);
p.text(g.track, track_x, track_y+5);
for_each(all_option_buttons, function(b) { b.draw(); });
};
obj.mouse_click = function(x, y) {
for_each(all_option_buttons, function(b) { b.click(x, y); });
};
return obj;
};