-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_menu.cpp
160 lines (126 loc) · 2.78 KB
/
main_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
#include <allegro.h>
#include "common.h"
#include "game.h"
#include "main_menu.h"
extern BITMAP* doubleBuffer;
extern volatile int secTicker;
const Vect2_t startElement = { 0 , 200 };
const Vect2_t optionsElement = { 0 , 250 };
const Vect2_t creditsElement = { 0 , 300 };
const Vect2_t exitElement = { 0 , 350 };
void MM_Init( pMainMenu_t pMenu , int timeToShow )
{
pMenu->timeToDemo = timeToShow;
pMenu->currentIndex = MAIN_MENU_ELEMENT_START;
}
void MM_HandleInput( pMainMenu_t pMenu )
{
}
void MM_AdvanceSelection( pMainMenu_t pMenu )
{
// handle wrap around case
if( pMenu->currentIndex == MAIN_MENU_ELEMENT_EXIT )
{
pMenu->currentIndex = MAIN_MENU_ELEMENT_START;
}
else if( pMenu->currentIndex <= MAIN_MENU_ELEMENT_EXIT && pMenu->currentIndex >= MAIN_MENU_ELEMENT_START )
{
pMenu->currentIndex++;
}
else
{
}
}
void MM_RetreatSelection( pMainMenu_t pMenu )
{
if( pMenu->currentIndex == MAIN_MENU_ELEMENT_START )
{
pMenu->currentIndex = MAIN_MENU_ELEMENT_EXIT;
}
else if( pMenu->currentIndex <= MAIN_MENU_ELEMENT_EXIT && pMenu->currentIndex >= MAIN_MENU_ELEMENT_START )
{
pMenu->currentIndex--;
}
else
{
}
}
void MM_MakeSelection( pMainMenu_t pMenu )
{
int selection = pMenu->currentIndex;
switch( selection )
{
case MAIN_MENU_ELEMENT_START:
{
break;
}
case MAIN_MENU_ELEMENT_OPTIONS:
{
break;
}
case MAIN_MENU_ELEMENT_CREDITS:
{
break;
}
case MAIN_MENU_ELEMENT_EXIT:
{
break;
}
}
}
r_boolean MM_Run( pMainMenu_t pMenu )
{
static int runningTime = secTicker;
runningTime -= secTicker;
// exit to demo if time
if( runningTime >= MAIN_MENU_TIME_TO_DEMO )
{
return r_false;
}
// handle key presses
if( key[ KEY_UP ] )
{
MM_RetreatSelection( pMenu );
}
else if( key[ KEY_DOWN ] )
{
MM_AdvanceSelection( pMenu );
}
else if( key[ KEY_ENTER ] )
{
return r_false;
}
MM_RenderMenu( pMenu );
return r_true;
}
void MM_RenderMenu( pMainMenu_t pMenu )
{
for( int element = 0, color = 0;element < MAIN_MENU_ELEMENTS;element++ )
{
// render the selected element differently than the others.
color = ( element == pMenu->currentIndex ) ? ( makecol( 255 , 255 , 255 ) ) : ( makecol( 128 , 128 , 128 ) );
switch( element )
{
case MAIN_MENU_ELEMENT_START:
{
textout_ex( screen , font , "Start" , startElement.x , startElement.y , color , 1 );
break;
}
case MAIN_MENU_ELEMENT_OPTIONS:
{
textout_ex( screen , font , "Options" , optionsElement.x , optionsElement.y , color , 1 );
break;
}
case MAIN_MENU_ELEMENT_CREDITS:
{
textout_ex( screen , font , "Credits" , creditsElement.x , creditsElement.y , color , 1 );
break;
}
case MAIN_MENU_ELEMENT_EXIT:
{
textout_ex( screen , font , "Exit" , exitElement.x , exitElement.y , color , 1 );
break;
}
}
}
}