forked from adoptware/pinball
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmeny.cpp
122 lines (100 loc) · 3.03 KB
/
meny.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
/***************************************************************************
Simple meny test. A cube should be visible in the middle of the screen.
The arrow keys rotates the cube.
***************************************************************************/
#include "Engine.h"
#include "Camera.h"
#include "Cube.h"
#include "KeyRotBehavior.h"
#include "Keyboard.h"
#include "Meny.h"
#include "EmFont.h"
#include "Config.h"
/** Main */
void sndFunc(Meny * m) {
if (Config::getInstance()->useSound()) {
Config::getInstance()->setSound(false);
m->setName("sound off");
} else {
Config::getInstance()->setSound(true);
m->setName("sound on");
}
cerr << "sound" << endl;
}
void grxFunc(Meny * m) {
if (Config::getInstance()->useFullScreen()) {
Config::getInstance()->setFullScreen(false);
m->setName("graphics windowed");
} else {
Config::getInstance()->setFullScreen(true);
m->setName("graphics fullscreen");
}
cerr << "graphics" << endl;
}
int main(int argc, char *argv[]) {
cerr << "Simple emilia test." << endl;
// Create the engine.
Engine* engine = new Engine(argc, argv);
engine->setLightning(0.5f, 0.1f);
// Add a camera. Move a bit.
Camera* camera = new Camera();
Group* groupCamera = new Group();
engine->add(groupCamera);
groupCamera->setCamera(camera);
groupCamera->setTranslation(0, 0, 3);
engine->setEngineCamera(groupCamera);
// Add a cube.
Cube* cube = new Cube(1.0, 1.0, 1.0, 0.0, 1.0);
Group* groupCube = new Group();
engine->add(groupCube);
groupCube->addShape3D(cube);
// Add a behavior to the cube
KeyRotBehavior* keyRBeh = new KeyRotBehavior();
groupCube->addBehavior(keyRBeh);
// Load a font
EmFont* font = EmFont::getInstance();
font->loadFont("test/font_16.pcx");
// Create the meny
Meny* meny = new Meny("meny", engine);
Meny* menyresume = new Meny("resume", engine);
menyresume->setAction(EM_MENU_RESUME);
meny->addMeny(menyresume);
Meny* menycfg = new Meny("config", engine);
menycfg->setAction(EM_MENU_SUB);
meny->addMeny(menycfg);
Meny* menyexit = new Meny("exit", engine);
menyexit->setAction(EM_MENU_EXIT);
meny->addMeny(menyexit);
Meny* menysnd = new Meny("sound off", engine);
if (Config::getInstance()->useSound()) {
menysnd->setName("sound on");
}
menysnd->setAction(EM_MENU_SUB);
menysnd->setFunction(sndFunc);
menycfg->addMeny(menysnd);
Meny* menygrx = new Meny("graphics windowed", engine);
if (Config::getInstance()->useFullScreen()) {
menygrx->setName("graphics fullscreen");
}
menygrx->setAction(EM_MENU_SUB);
menygrx->setFunction(grxFunc);
menycfg->addMeny(menygrx);
Meny* menyctrl = new Meny("controls", engine);
menyctrl->setAction(EM_MENU_SUB);
menycfg->addMeny(menyctrl);
Meny* menyback = new Meny("back", engine);
menyback->setAction(EM_MENU_BACK);
menycfg->addMeny(menyback);
bool done = false;
while (!Keyboard::isKeyDown(SDLK_ESCAPE) && !done) {
engine->tick();
engine->render();
engine->swap();
if (Keyboard::isKeyDown(SDLK_SPACE)) {
if (meny->start() == EM_MENU_EXIT) done = true;
}
SDL_Delay(50);
}
delete(engine);
return 0;
}