/
OEMFMain.cpp
192 lines (180 loc) · 4.92 KB
/
OEMFMain.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
/*
* OEMFMain.cpp
* Oemfoeland 5
*
* Created by Jef Geskens on 27/12/05.
* Copyright 2005 Jef Geskens. All rights reserved.
*
*/
#include <math.h>
#include "OEMFMain.h"
#include "OEMFStorage.h"
#include "OEMFString.h"
#include "OEMFLevelEdit.h"
#include "OEMFGame.h"
OEMFMain :: OEMFMain(SDL_Surface * screen, char * execPath, unsigned int screenWidth, unsigned int screenHeight, unsigned int screenBpp)
: OEMFEnvironment(screen, execPath, screenWidth, screenHeight, screenBpp)
{
m_menuOptions = new string[5];
m_menuCount = 5;
m_menuOptions[0] = "NEW GAME";
m_menuOptions[1] = "HIGH SCORES";
m_menuOptions[2] = "OPTIONS";
m_menuOptions[3] = "LEVEL EDITOR";
m_menuOptions[4] = "EXIT";
}
OEMFMain :: ~OEMFMain(void)
{
}
void OEMFMain :: drawIntro(void)
{
clearWithColor(0xFF000000, false);
blitImage(images[IMG_INTRO], 0, 0);
SDL_UpdateRect(m_screen, 0, 0, m_screenWidth, m_screenHeight);
}
void OEMFMain :: run(void)
{
unsigned int menuIndex = 0;
unsigned int frames = 0;
unsigned int timepassed;
if (musicPlayer->isPlayingSong())
musicPlayer->stopSong();
string songfile = PREPATH "boiling.mp3";
musicPlayer->playSongAtPath(songfile.c_str());
drawIntro();
SDL_Event event;
int done = 0;
while ( !done) {
timepassed = SDL_GetTicks();
OEMF_LOCKSCREEN;
clearWithColor(0xFF000000, false);
OEMF_UNLOCKSCREEN;
blitImage(images[IMG_INTRO], 0, 0);
for (unsigned int i = 0; i < m_menuCount; i++)
fonts[FNT_MENU]->blitText(this, m_menuOptions[i].c_str(), 160, 240 + i * 32, 480, false);
blitImage(images[IMG_OEMFOE], 128, (unsigned int) (240 + menuIndex * 32 + sin(frames / 2.0) * 8));
SDL_UpdateRect(m_screen, 128, 232, 512, 248);
/* Check for events */
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_MOUSEMOTION:
break;
case SDL_MOUSEBUTTONDOWN:
break;
case SDL_KEYDOWN:
if (event.key.keysym.sym == SDLK_ESCAPE)
{
done = 1;
}
else if (event.key.keysym.sym == SDLK_UP)
{
menuIndex = (menuIndex - 1 + m_menuCount) % m_menuCount;
musicPlayer->playSound(sounds[SND_TOK]);
}
else if (event.key.keysym.sym == SDLK_DOWN)
{
menuIndex = (menuIndex + 1) % m_menuCount;
musicPlayer->playSound(sounds[SND_TOK]);
}
else if (event.key.keysym.sym == SDLK_p)
{
SDL_SaveBMP(m_screen, "screenshot.bmp");
}
else if (event.key.keysym.sym == SDLK_RETURN)
{
musicPlayer->playSound(sounds[SND_TIK]);
if (menuIndex == 4)
{
fadeOut();
done = 1;
}
else if (menuIndex == 0) // new game
{
fadeOut();
OEMFGame * game = new OEMFGame(m_screen, m_execPath, m_screenWidth, m_screenHeight, m_screenBpp);
game->run();
delete game;
drawIntro();
}
else if (menuIndex == 3) // level editor
{
fadeOut();
OEMFLevelEdit * leveledit = new OEMFLevelEdit(m_screen, m_execPath, m_screenWidth, m_screenHeight, m_screenBpp);
leveledit->run();
delete leveledit;
drawIntro();
}
else if (menuIndex == 2) // options
{
unsigned int choice = 0;
string * options = new string[2];
while (choice != 2) // not exit
{
if (musicEnabled)
options[0] = "Turn Music Off";
else
options[0] = "Turn Music On";
options[1] = "Toggle Fullscreen";
drawIntro();
choice = chooseList(2 /* exit */, "Options", options, 2);
if (choice == 0)
{
musicEnabled = !musicEnabled;
if (!musicEnabled)
{
if (musicPlayer->isPlayingSong())
musicPlayer->stopSong();
}
else
{
musicPlayer->playSongAtPath(songfile.c_str());
}
}
else if (choice == 1)
{
if (fullscreenMode)
{
m_screen = SDL_SetVideoMode(m_screenWidth, m_screenHeight, m_screenBpp, SDL_SWSURFACE);
m_fb = (Uint32 *) m_screen->pixels;
m_pitch = (Uint32) m_screen->pitch / 4;
fullscreenMode = false;
}
else
{
m_screen = SDL_SetVideoMode(m_screenWidth, m_screenHeight, m_screenBpp, SDL_SWSURFACE | SDL_FULLSCREEN);
m_fb = (Uint32 *) m_screen->pixels;
m_pitch = (Uint32) m_screen->pitch / 4;
fullscreenMode = true;
}
choice = 2;
}
}
drawIntro();
}
else
{
fadeOut();
fonts[FNT_MENU]->blitCenterText(this, "NOT AVAILABLE YET", 240, m_screenWidth);
SDL_UpdateRect(m_screen, 0, 0, m_screenWidth, m_screenHeight);
SDL_Delay(2000);
string test = fonts[FNT_MENU]->inputText(this, "default", 32, 32, 10);
drawIntro();
}
}
break;
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
frames++;
// 30 FPS
timepassed = SDL_GetTicks() - timepassed;
if (timepassed <= 33)
SDL_Delay(33 - timepassed);
}
}