-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu.cpp
347 lines (304 loc) · 9.73 KB
/
menu.cpp
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#include "menu.h"
#include "configure.h"
#include "game.h"
#include "player.h"
void Menu::Begin()
{
titleTint = 0;
titleTintDelay = 0;
titleTextY = -200;
playerTint = 0;
MinPlayerCount = 6;
buttonState = 0;
buttonStateDelay = 0;
gameCountDown = START_GAME_COUNTDOWN;
gameCountDownDelay = 0;
gameCountDownActive = false;
titleFont = al_load_font( "resource/forte.ttf", CurrentConfiguration->ScreenHeight / 8, 0 );
menuFont = al_load_font( "resource/forte.ttf", CurrentConfiguration->ScreenHeight / 48, 0 );
titleBkg = al_load_bitmap( "resource/title.png" );
buttonUp = al_load_bitmap( "resource/button_up.png" );
buttonDown = al_load_bitmap( "resource/button_down.png" );
if( PlayerList->count > 0 )
{
for( int idx = 0; idx < PlayerList->count; idx++ )
{
Player* p = (Player*)PlayerList->ItemAt(idx);
p->State = STATE_AWAIT_ENTRY;
}
}
if( voice != 0 )
{
menuMusic = al_load_audio_stream( "resource/wandschrank-gurkenbalken.ogg", 4, 2048 );
al_set_audio_stream_playmode( menuMusic, ALLEGRO_PLAYMODE_LOOP );
al_attach_audio_stream_to_mixer( menuMusic, mixer );
al_set_audio_stream_playing( menuMusic, true );
}
}
void Menu::Pause()
{
if( voice != 0 )
{
al_set_audio_stream_playing( menuMusic, false );
}
}
void Menu::Resume()
{
if( voice != 0 )
{
al_set_audio_stream_playing( menuMusic, true );
}
}
void Menu::Finish()
{
al_destroy_font( menuFont );
al_destroy_font( titleFont );
al_destroy_bitmap( buttonDown );
al_destroy_bitmap( buttonUp );
al_destroy_bitmap( titleBkg );
if( voice != 0 )
{
al_set_audio_stream_playing( menuMusic, false );
al_destroy_audio_stream( menuMusic );
}
}
void Menu::Event(ALLEGRO_EVENT *e)
{
Player* p;
bool found = false;
switch( e->type )
{
case ALLEGRO_EVENT_KEY_DOWN:
if( e->keyboard.keycode == ALLEGRO_KEY_LEFT && MinPlayerCount > 0 )
MinPlayerCount--;
if( e->keyboard.keycode == ALLEGRO_KEY_RIGHT && MinPlayerCount < 32 )
MinPlayerCount++;
break;
case ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN:
titleTint = 255;
playerTint = 128;
titleTextY = 20;
for( int i = 0; i < PlayerList->count; i++ )
{
p = (Player*)PlayerList->ItemAt(i);
if( p->Joystick == e->joystick.id )
{
if( p->State < STATE_READY )
p->State++;
p->ProcessInput( e );
found = true;
break;
}
}
if( !found )
{
p = new Player();
p->Joystick = e->joystick.id;
PlayerList->AddToEnd( p );
}
break;
case ALLEGRO_EVENT_JOYSTICK_BUTTON_UP:
case ALLEGRO_EVENT_JOYSTICK_AXIS:
for( int i = 0; i < PlayerList->count; i++ )
{
p = (Player*)PlayerList->ItemAt(i);
if( p->Joystick == e->joystick.id )
{
p->ProcessInput( e );
break;
}
}
break;
case ALLEGRO_EVENT_AUDIO_STREAM_FINISHED:
/*
al_set_audio_stream_playing( menuMusic, false );
al_rewind_audio_stream( menuMusic );
al_set_audio_stream_playing( menuMusic, true );
*/
break;
}
}
void Menu::Update()
{
if( titleTint < 255 )
{
titleTint += 2;
if( titleTint > 255 )
titleTint = 255;
} else if( playerTint < 128 ) {
playerTint += 4;
}
if( titleTextY < 20 )
titleTextY += 3;
buttonStateDelay = (++buttonStateDelay) % 6;
if( buttonStateDelay == 0 )
buttonState = 1 - buttonState;
if( PlayerList->count > 0 )
{
int ready = 0;
for( int idx = 0; idx < PlayerList->count; idx++ )
{
Player* p = (Player*)PlayerList->ItemAt(idx);
if( p->State == STATE_READY )
{
ready++;
} else {
switch( p->State )
{
case STATE_SELECT_GENDER:
if( p->DidInputChange(INPUT_LEFT, true) || p->DidInputChange(INPUT_RIGHT, true) )
p->Gender = 1 - p->Gender;
break;
case STATE_SELECT_HAIR:
if( (p->UserInput & INPUT_LEFT) != 0 )
{
p->HairHue += 1.0;
if( p->HairHue >= 360.0 )
p->HairHue -= 360.0;
}
if( (p->UserInput & INPUT_RIGHT) != 0 )
{
p->HairHue -= 1.0;
if( p->HairHue < 0.0 )
p->HairHue += 360.0;
}
if( (p->UserInput & INPUT_UP) != 0 && p->HairLum < 1.0 )
{
p->HairLum += 0.01;
if( p->HairLum > 1.0 )
p->HairLum = 1.0;
}
if( (p->UserInput & INPUT_DOWN) != 0 && p->HairLum > 0.0 )
{
p->HairLum -= 0.01;
if( p->HairLum < 0.0 )
p->HairLum = 0.0;
}
break;
case STATE_SELECT_SKIN:
if( p->DidInputChange(INPUT_LEFT, true) || p->DidInputChange(INPUT_RIGHT, true) )
p->SkinLum = 1.0 - p->SkinLum;
break;
case STATE_SELECT_TEAM:
if( (p->UserInput & INPUT_LEFT) != 0 )
{
p->TeamHue += 2.0;
if( p->TeamHue >= 360.0 )
p->TeamHue -= 360.0;
}
if( (p->UserInput & INPUT_RIGHT) != 0 )
{
p->TeamHue -= 2.0;
if( p->TeamHue < 0.0 )
p->TeamHue += 360.0;
}
if( (p->UserInput & INPUT_UP) != 0 && p->TeamLum < 1.0 )
{
p->TeamLum += 0.01;
if( p->TeamLum > 1.0 )
p->TeamLum = 1.0;
}
if( (p->UserInput & INPUT_DOWN) != 0 && p->TeamLum > 0.0 )
{
p->TeamLum -= 0.01;
if( p->TeamLum < 0.0 )
p->TeamLum = 0.0;
}
break;
}
}
p->Update();
}
if( PlayerList->count == ready )
{
gameCountDownActive = true;
gameCountDownDelay = (++gameCountDownDelay) % SCREEN_FPS;
if( gameCountDownDelay == 0 )
gameCountDown--;
if( gameCountDown == 0 )
{
gameCountDownActive = false;
gameCountDown = START_GAME_COUNTDOWN;
Game* g = new Game();
g->fillAIToCount = MinPlayerCount;
GameStack->Push( (Stage*)g );
}
} else {
// Wait for players to select character data
gameCountDownActive = false;
gameCountDown = START_GAME_COUNTDOWN;
}
}
}
void Menu::Render()
{
int plyBoxW = ((CurrentConfiguration->ScreenWidth - 40) / 4) - 10;
int plyBoxH = CurrentConfiguration->ScreenHeight / 4;
//al_clear_to_color( al_map_rgb( 0, 0, 0 ) );
al_draw_tinted_scaled_bitmap( titleBkg, al_map_rgb( titleTint, titleTint, titleTint ), 0, 0, al_get_bitmap_width(titleBkg), al_get_bitmap_height(titleBkg), 0, 0, CurrentConfiguration->ScreenWidth, CurrentConfiguration->ScreenHeight, 0 );
al_draw_text( titleFont, al_map_rgb(0, 0, 0), 12, titleTextY + 2, ALLEGRO_ALIGN_LEFT, "British Bulldogs" );
al_draw_text( titleFont, al_map_rgb(255, 255, 255), 10, titleTextY, ALLEGRO_ALIGN_LEFT, "British Bulldogs" );
for( int plyIdx = 0; plyIdx < 4; plyIdx++ )
{
RenderPlayerBox( (plyIdx * 2), 20 + (plyBoxW * plyIdx) + 5, (CurrentConfiguration->ScreenHeight / 3), plyBoxW - 10, plyBoxH );
RenderPlayerBox( (plyIdx * 2) + 1, 20 + (plyBoxW * plyIdx) + 5, (CurrentConfiguration->ScreenHeight / 3) + plyBoxH + 10, plyBoxW - 10, plyBoxH );
}
char numJoy[200];
sprintf( numJoy, "AI Fill To %d Players", MinPlayerCount );
al_draw_text( menuFont, al_map_rgb( 128, 128, 255 ), CurrentConfiguration->ScreenWidth, 48, ALLEGRO_ALIGN_RIGHT, numJoy );
sprintf( numJoy, "%d Joystick(s) Found", al_get_num_joysticks() );
al_draw_text( menuFont, al_map_rgb( 0, 0, 0 ), CurrentConfiguration->ScreenWidth, CurrentConfiguration->ScreenHeight - 48, ALLEGRO_ALIGN_RIGHT, numJoy );
if( gameCountDownActive )
{
sprintf( numJoy, "Starts In %d", gameCountDown );
al_draw_text( titleFont, al_map_rgb( 0, 0, 0 ), (CurrentConfiguration->ScreenWidth / 2) + 2, (CurrentConfiguration->ScreenHeight / 2) + 2, ALLEGRO_ALIGN_CENTRE, numJoy );
al_draw_text( titleFont, al_map_rgb( 255, 255, 128 ), CurrentConfiguration->ScreenWidth / 2, CurrentConfiguration->ScreenHeight / 2, ALLEGRO_ALIGN_CENTRE, numJoy );
}
#ifdef _DEBUG
for( int idx = 0; idx < al_get_num_joysticks(); idx++ )
{
ALLEGRO_JOYSTICK* j = al_get_joystick( idx );
ALLEGRO_JOYSTICK_STATE je;
al_get_joystick_state( j, &je );
sprintf( numJoy, "%d: %f : %d: %f", 0, je.stick[0].axis[0], 1, je.stick[0].axis[1] );
al_draw_text( menuFont, al_map_rgb( 0, 255, 255 ), 400, idx * 40, ALLEGRO_ALIGN_LEFT, numJoy );
}
#endif
}
void Menu::RenderPlayerBox( int PlayerIdx, int BoxX, int BoxY, int BoxW, int BoxH )
{
al_draw_filled_rectangle( BoxX, BoxY, BoxX + BoxW, BoxY + BoxH, al_map_rgba( 0, 0, 0, playerTint ) );
if( playerTint < 128 )
return;
if( PlayerList->count < PlayerIdx + 1 )
{
al_draw_bitmap( (buttonState == 0 ? buttonUp : buttonDown), BoxX + (BoxW / 2) - (al_get_bitmap_width(buttonDown) / 2), BoxY + (BoxH / 2) - (al_get_bitmap_height(buttonDown) / 2), 0 );
} else {
Player* p = (Player*)PlayerList->ItemAt( PlayerIdx );
if( p->State == STATE_AWAIT_ENTRY )
{
al_draw_bitmap( (buttonState == 0 ? buttonUp : buttonDown), BoxX + (BoxW / 2) - (al_get_bitmap_width(buttonDown) / 2), BoxY + (BoxH / 2) - (al_get_bitmap_height(buttonDown) / 2), 0 );
} else {
int ScaleSize = ((BoxW <= BoxH ? BoxW : BoxH) / 5) * 4;
p->Render( BoxX + (BoxW / 2), BoxY + (BoxH / 2) + (ScaleSize / 2), ScaleSize, ScaleSize );
switch( p->State )
{
case STATE_SELECT_GENDER:
al_draw_text( menuFont, al_map_rgb( 255, 255, 255 ), BoxX + (BoxW / 2), BoxY + BoxH - al_get_font_line_height( menuFont ), ALLEGRO_ALIGN_CENTRE, "< Gender >" );
break;
case STATE_SELECT_SKIN:
al_draw_text( menuFont, al_map_rgb( 255, 255, 255 ), BoxX + (BoxW / 2), BoxY + BoxH - al_get_font_line_height( menuFont ), ALLEGRO_ALIGN_CENTRE, "< Skin >" );
break;
case STATE_SELECT_HAIR:
al_draw_text( menuFont, al_map_rgb( 255, 255, 255 ), BoxX + (BoxW / 2), BoxY + BoxH - al_get_font_line_height( menuFont ), ALLEGRO_ALIGN_CENTRE, "< Hair >" );
break;
case STATE_SELECT_TEAM:
al_draw_text( menuFont, al_map_rgb( 255, 255, 255 ), BoxX + (BoxW / 2), BoxY + BoxH - al_get_font_line_height( menuFont ), ALLEGRO_ALIGN_CENTRE, "< Colour >" );
break;
case STATE_READY:
al_draw_text( menuFont, al_map_rgb( 255, 255, 255 ), BoxX + (BoxW / 2), BoxY + BoxH - al_get_font_line_height( menuFont ), ALLEGRO_ALIGN_CENTRE, "Ready" );
break;
}
}
}
}