1 /*
2 * DESCRIPCION DEL JUEGO
3 * Copyright (C) 2007 Javier P�rez Pacheco
4 *
5 * Este juego tienen licencia Creative Commons y se permite
6 * su modificacion y utilizacion libremente siempre y cuando se
7 * cite al autor original y se comparta con la misma licencia.
8 * No se permite su uso comercial.
9 *
10 * Para mas informacion visite la web:
11 * http://creativecommons.org/licenses/by-nc-sa/2.0/es/
12 *
13 * PROGRAMADOR
14 * Javier P�rez Pacheco
15 * Cadiz (Spain)
16 * javielinux@gmail.com
17 *
18 * GRAFISMO Y 3D
19 * Jesus Carrasco
20 * Cadiz (Spain)
21 * carrasco.carrasco@gmail.com
22 *
23 * MUSICA Y GRAFISMO
24 * Shano Lores
25 * Cadiz (Spain)
26 * shanakla@gmail.com
27 *
28 */
29
30 #include "application.h"
31
32
Application(int w,int h,string titleWindow)33 Application::Application(int w, int h, string titleWindow) : World (w, h, titleWindow) {
34
35 if (existDataDirectory) {
36 // configuration files
37
38 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
39 SDL_EnableUNICODE(1);
40
41 changeLanguage = false;
42
43 if (Options::GetInstance()->getNItems() == 0) {
44 Options::GetInstance()->addItem("fullscreen", "true");
45 Options::GetInstance()->addItem("helpactived", "true");
46 Options::GetInstance()->addItem("music", "3");
47 Options::GetInstance()->addItem("effects", "3");
48 Options::GetInstance()->addItem("debug", "false");
49 Options::GetInstance()->addItem("lang", "es");
50 Options::GetInstance()->addItem("user", "-1");
51 Options::GetInstance()->addItem("scene", "");
52 Options::GetInstance()->save();
53 changeLanguage = true;
54 }
55
56 Options::GetInstance()->addItem("mission", "-1");
57 Options::GetInstance()->save();
58
59 if (Options::GetInstance()->getValue("debug") == "true") {
60 Debug::GetInstance()->setDebug(true);
61 }
62
63 Users::GetInstance()->load("user.xml");
64
65 if (Users::GetInstance()->getCurrentUser()==NULL) {
66 Options::GetInstance()->setValue("user", "-1");
67 Options::GetInstance()->save();
68 }
69
70 Missions::GetInstance()->load();
71
72 // sounds
73
74 Sounds::GetInstance()->init();
75
76 Sound::setPorcentVolumeByCategory("default", 80);
77 Sound::setPorcentVolumeByCategory("music", 20*(Options::GetInstance()->getValueToInt("music")));
78 Sound::setPorcentVolumeByCategory("high_music", 20*(Options::GetInstance()->getValueToInt("music")+1));
79 Sound::setPorcentVolumeByCategory("low_music", 20*(Options::GetInstance()->getValueToInt("music")-1));
80 Sound::setPorcentVolumeByCategory("musicgame", (20*(Options::GetInstance()->getValueToInt("music")))/3);
81 Sound::setPorcentVolumeByCategory("effect", 20*(Options::GetInstance()->getValueToInt("effects")));
82 Sound::setPorcentVolumeByCategory("high_effect", 20*(Options::GetInstance()->getValueToInt("effects")+1));
83 Sound::setPorcentVolumeByCategory("low_effect", 20*(Options::GetInstance()->getValueToInt("effects")-1));
84
85 Sounds::GetInstance()->addSoundFromData("beep0", "effect", "sound/beep0.ogg", true);
86 Sounds::GetInstance()->addSoundFromData("beep1", "effect", "sound/beep1.ogg", true);
87 Sounds::GetInstance()->addSoundFromData("click0", "effect", "sound/click0.ogg", true);
88 Sounds::GetInstance()->addSoundFromData("click1", "effect", "sound/click1.ogg", true);
89
90 // fonts
91
92 Fonts::GetInstance()->addFontBitMap("font-titles", (string)DATA_DIR + "/fonts/font-titles.png", false);
93 Fonts::GetInstance()->addFontBitMap("font-wall0", (string)DATA_DIR + "/fonts/font-wall0.png", false);
94 Fonts::GetInstance()->addFontBitMap("font-wall1", (string)DATA_DIR + "/fonts/font-wall1.png", false);
95 Fonts::GetInstance()->addFontBitMap("font-wall2", (string)DATA_DIR + "/fonts/font-wall2.png", false);
96 Fonts::GetInstance()->addFontBitMap("font-wall3", (string)DATA_DIR + "/fonts/font-wall3.png", false);
97 Fonts::GetInstance()->addFontBitMap("font-wall4", (string)DATA_DIR + "/fonts/font-wall4.png", false);
98 Fonts::GetInstance()->addFontBitMap("font-wall5", (string)DATA_DIR + "/fonts/font-wall5.png", false);
99 Fonts::GetInstance()->addFontBitMap("font-computer", (string)DATA_DIR + "/fonts/font-computer.png");
100 Fonts::GetInstance()->addFontBitMap("font-texts", (string)DATA_DIR + "/fonts/font-texts.png");
101
102
103 TypeObjectsScenary::GetInstance()->load();
104
105 Language::GetInstance()->setLang(Options::GetInstance()->getValue("lang"));
106
107 loadScenes();
108 modeScreen();
109
110 // messagebox, input and alerts
111
112 createStaticsElements_InScene();
113 Scene::msg_fontTitle = "font-computer";
114 Scene::msg_fontText = "font-texts";
115 Scene::msg_fontButtons = "font-computer";
116 Scene::msg_fontEntry = "font-computer";
117
118 Cursor::GetInstance()->setUseImageCursor(true);
119 Cursor::GetInstance()->addCursor("default", "/cursors/default.png");
120 Cursor::GetInstance()->addCursor("help", "/cursors/help.png");
121 Cursor::GetInstance()->addCursor("rotate", "/cursors/rotate.png");
122 Cursor::GetInstance()->setCursor("default");
123 Cursor::GetInstance()->setFontText("font-texts");
124 Cursor::GetInstance()->setScaleAlt(0.8);
125 Cursor::GetInstance()->setSizeBorder(2);
126
127 }
128
129 }
130
createStaticsElements_InScene()131 void Application::createStaticsElements_InScene () {
132 char tmp[8];
133
134 Scene::hasMsg_bg = true;
135 Scene::hasMsg_title = false;
136
137 Scene::msg_bgMessage = new Element();
138 Scene::msg_bgMessage->setAlign(ALIGN_CENTER);
139 Scene::msg_bgMessage->setVAlign(VALIGN_CENTER);
140 Scene::msg_bgMessage->setXY(World::width/2, 250);
141
142 Scene::msg_bgMessage->addFrameFileFromData("/windows/" + Language::GetInstance()->getFilename("showmessage", "png"));
143
144 Scene::msg_bgAlert = new Element();
145 Scene::msg_bgAlert->setAlign(ALIGN_CENTER);
146 Scene::msg_bgAlert->setVAlign(VALIGN_CENTER);
147 Scene::msg_bgAlert->setXY(World::width/2, 250);
148
149 Scene::msg_bgAlert->addFrameFileFromData("/windows/" + Language::GetInstance()->getFilename("showalert", "png"));
150
151 strcpy(tmp, "Text");
152
153 Scene::msg_text = new Element();
154 Scene::msg_text->setAlign(ALIGN_CENTER);
155 Scene::msg_text->setVAlign(VALIGN_TOP);
156 Scene::msg_text->setX(World::width/2);
157 Scene::msg_text->setY(250);
158
159 Scene::msg_text->addFrameText(Fonts::GetInstance()->getDefaultFont(), tmp, ALIGN_CENTER);
160
161 Scene::posXBAcceptInAlert = 263;
162 Scene::posXBCancelInAlert = 540;
163
164 Scene::msg_bAccept = new Button();
165 Scene::msg_bAccept->addParameter("type", "accept");
166 Scene::msg_bAccept->setScales(0.4, 0.45);
167 Scene::msg_bAccept->setAlign(ALIGN_CENTER);
168 Scene::msg_bAccept->setVAlign(VALIGN_CENTER);
169 Scene::msg_bAccept->setX(World::width/4);
170 Scene::msg_bAccept->setY(383);
171 Scene::msg_bAccept->setRGB(0,255,0);
172
173 if (Language::GetInstance()->getText("accept")!="-") {
174 sprintf(tmp, Language::GetInstance()->getText("accept").c_str());
175 } else {
176 sprintf(tmp, "Accept");
177 }
178 Scene::msg_bAccept->imageOut(Fonts::GetInstance()->getSurface_TextBitMap(Fonts::GetInstance()->getDefaultFont(), ALIGN_CENTER, tmp));
179 Scene::msg_bAccept->setAnimation("out");
180
181
182 Scene::msg_bCancel = new Button();
183 Scene::msg_bCancel->addParameter("type", "cancel");
184 Scene::msg_bCancel->setScales(0.4, 0.45);
185 Scene::msg_bCancel->setAlign(ALIGN_CENTER);
186 Scene::msg_bCancel->setVAlign(VALIGN_CENTER);
187 Scene::msg_bCancel->setX((World::width/4)*3);
188 Scene::msg_bCancel->setY(383);
189 Scene::msg_bCancel->setRGB(255,0,0);
190
191 if (Language::GetInstance()->getText("cancel")!="-") {
192 sprintf(tmp, Language::GetInstance()->getText("cancel").c_str());
193 } else {
194 sprintf(tmp, "Cancel");
195 }
196 Scene::msg_bCancel->imageOut(Fonts::GetInstance()->getSurface_TextBitMap(Fonts::GetInstance()->getDefaultFont(), ALIGN_CENTER, tmp));
197 Scene::msg_bCancel->setAnimation("out");
198
199 Scene::msg_entry = new Entry(NULL, 550, 40, 0, 10);
200 Scene::msg_entry->setNoSigns(true);
201 Scene::msg_entry->setX((World::width/2)-200);
202 Scene::msg_entry->setY(310);
203 Scene::msg_entry->setActive(true);
204 Scene::msg_entry->setDrawBox(false);
205
206 }
207
loadScenes()208 void Application::loadScenes() {
209 s_menu = new SceneMenu();
210 s_menu->setId(1);
211 s_menu->setWorld((World*)this);
212 addScene("menu", s_menu);
213
214 s_game = new SceneGame();
215 s_game->setId(2);
216 s_game->setWorld((World*)this);
217 addScene("game", s_game);
218
219 s_editgame = new SceneEditGame();
220 s_editgame->setId(3);
221 s_editgame->setWorld((World*)this);
222 addScene("editgame", s_editgame);
223
224 s_createmission = new SceneCreateMission();
225 s_createmission->setId(4);
226 s_createmission->setWorld((World*)this);
227 addScene("createmission", s_createmission);
228
229 s_mainanim = new SceneAnimation();
230 s_mainanim->setId(5);
231 s_mainanim->setWorld((World*)this);
232 s_mainanim->setDirectory(string(DATA_DIR) + "/animation");
233 s_mainanim->setNameSceneWhenScape("menu");
234 s_mainanim->setDrawCursor(false);
235 addScene("anim", s_mainanim);
236
237 s_infotown = new SceneInfoTown();
238 s_infotown->setId(6);
239 s_infotown->setWorld((World*)this);
240 s_infotown->setNameSceneWhenScape("game");
241 addScene("infotown", s_infotown);
242
243 s_changelang = new SceneChangeLanguage();
244 s_changelang->setId(7);
245 s_changelang->setWorld((World*)this);
246 addScene("changelang", s_changelang);
247
248 s_credits = new SceneCredits();
249 s_credits->setId(8);
250 s_credits->setWorld((World*)this);
251 s_credits->setDrawCursor(false);
252 addScene("credits", s_credits);
253
254 }
255
execute()256 void Application::execute() {
257
258 if (!existDataDirectory) {
259 printf("Don't exist directory data: %s\n", DATA_DIR);
260 return;
261 }
262
263 if (Options::GetInstance()->getValue("scene") != "") {
264 currentScene = getScene(Options::GetInstance()->getValue("scene"))->getId();
265 } else {
266 if (changeLanguage) {
267 currentScene = getScene("changelang")->getId();
268 } else {
269 currentScene = getScene("anim")->getId();
270 }
271 }
272
273 int done = 0;
274
275 while (done == 0) {
276
277 switch (currentScene) {
278 // *********************
279 // MENU
280 // *********************
281 case 1:
282 if (!s_menu->getIsLoad()) { s_menu->load(); }
283 if (s_menu->drawScene()) {
284 int idNextScene = loadScene(s_menu->getNextScene());
285 if ( idNextScene == -1 ) {
286 done = 1;
287 } else {
288 currentScene = idNextScene;
289 }
290 s_menu->unLoad();
291 }
292 break;
293 // *********************
294 // GAME
295 // *********************
296 case 2:
297 if (!s_game->getIsLoad()) { s_game->load(); }
298 if (s_game->drawScene()) {
299 int idNextScene = loadScene(s_game->getNextScene());
300 if ( idNextScene == -1 ) {
301 done = 1;
302 } else {
303 currentScene = idNextScene;
304 }
305 s_game->unLoad();
306 }
307 break;
308 // *********************
309 // EDIT GAME
310 // *********************
311 case 3:
312 if (!s_editgame->getIsLoad()) { s_editgame->load(); }
313 if (s_editgame->drawScene()) {
314 int idNextScene = loadScene(s_editgame->getNextScene());
315 if ( idNextScene == -1 ) {
316 done = 1;
317 } else {
318 currentScene = idNextScene;
319 }
320 s_editgame->unLoad();
321 }
322 break;
323 // *********************
324 // EDIT CREATE MISION
325 // *********************
326 case 4:
327 if (!s_createmission->getIsLoad()) { s_createmission->load(); }
328 if (s_createmission->drawScene()) {
329 int idNextScene = loadScene(s_createmission->getNextScene());
330 if ( idNextScene == -1 ) {
331 done = 1;
332 } else {
333 currentScene = idNextScene;
334 }
335 s_createmission->unLoad();
336 }
337 break;
338 // *********************
339 // ANIMATION
340 // *********************
341 case 5:
342 if (!s_mainanim->getIsLoad()) { s_mainanim->load(); }
343 if (s_mainanim->drawScene()) {
344 int idNextScene = loadScene(s_mainanim->getNextScene());
345 if ( idNextScene == -1 ) {
346 done = 1;
347 } else {
348 currentScene = idNextScene;
349 }
350 s_mainanim->unLoad();
351 }
352 break;
353 // *********************
354 // INFOTOWN
355 // *********************
356 case 6:
357 if (!s_infotown->getIsLoad()) { s_infotown->load(); }
358 if (s_infotown->drawScene()) {
359 int idNextScene = loadScene(s_infotown->getNextScene());
360 if ( idNextScene == -1 ) {
361 done = 1;
362 } else {
363 currentScene = idNextScene;
364 }
365 s_infotown->unLoad();
366 }
367 break;
368 // *********************
369 // CHANGELANGUAGE
370 // *********************
371 case 7:
372 if (!s_changelang->getIsLoad()) { s_changelang->load(); }
373 if (s_changelang->drawScene()) {
374 int idNextScene = loadScene(s_changelang->getNextScene());
375 if ( idNextScene == -1 ) {
376 done = 1;
377 } else {
378 currentScene = idNextScene;
379 }
380 s_changelang->unLoad();
381 }
382 break;
383 // *********************
384 // CREDITS
385 // *********************
386 case 8:
387 if (!s_credits->getIsLoad()) { s_credits->load(); }
388 if (s_credits->drawScene()) {
389 int idNextScene = loadScene(s_credits->getNextScene());
390 if ( idNextScene == -1 ) {
391 done = 1;
392 } else {
393 currentScene = idNextScene;
394 }
395 s_credits->unLoad();
396 }
397 break;
398 }
399
400 Timer::GetInstance()->waitFrame();
401
402 }
403
404 unLoad();
405
406 }
407