Pac-Man Evolution
Loading...
Searching...
No Matches
ResourceManager.cpp
1/*----------------------------------------------------------------------
2Pac-Man Evolution - Roberto Prieto
3Copyright (C) 2018-2024 MegaStorm Systems
4contact@megastormsystems.com - http://www.megastormsystems.com
5
6This software is provided 'as-is', without any express or implied
7warranty. In no event will the authors be held liable for any damages
8arising from the use of this software.
9
10Permission is granted to anyone to use this software for any purpose,
11including commercial applications, and to alter it and redistribute it
12freely, subject to the following restrictions:
13
141. The origin of this software must not be misrepresented; you must not
15claim that you wrote the original software. If you use this software
16in a product, an acknowledgment in the product documentation would be
17appreciated but is not required.
182. Altered source versions must be plainly marked as such, and must not be
19misrepresented as being the original software.
203. This notice may not be removed or altered from any source distribution.
21
22------------------------------------------------------------------------
23
24Resource Manager
25
26------------------------------------------------------------------------ */
27
28#include "ResourceManager.h"
29#include "Pac-Man_Evolution.h"
30#include <chrono>
31
32extern unsigned char pme_icon[];
33extern int pme_icon_size;
34
35// Singleton stuff
36ResourceManager* ResourceManager::mInstance = nullptr;
37
38// Create a single instance
39ResourceManager& ResourceManager::Instance()
40{
41 if(!mInstance) mInstance = new(std::nothrow) ResourceManager;
42 return *mInstance;
43}
44
46void ResourceManager::Terminate()
47{
48 if(mInstance) delete mInstance;
49 mInstance = nullptr;
50}
51
52ResourceManager::ResourceManager()
53{
54 bPacManDeathAnim = 1;
55 guiMenu = guiGame = 0;
56 fntConsole = fntInfo = fntScore = 0;
57 musMenu[0] = musMenu[1] = musMenu[2] = 0;
58 musGame[0] = musGame[1] = musGame[2] = musGame[3] = 0;
59 sndThunder = sndClickOK = sndClickCancel = sndClickCancel2 = sndExit = 0;
60 sndGameAbort = sndGameOver = sndGameStarting = sndGamePlayerDeath = sndGameEatPellet = sndGameEatPelletPower = sndGameEatGhost = 0;
61 imgIcon = imgMenu = imgHallOfFame = 0;
62 curArrow = 0;
63 sprPacman = sprGhostRed = sprGhostPink = sprGhostBlue = sprGhostOrange = sprTargets = 0;
64 sprPellet = sprPelletPower = 0;
65}
66
67ResourceManager::~ResourceManager()
68{
69 free();
70}
71
72// Load all resources. Avoid double loads and manager errors.
73Sint32 ResourceManager::load()
74{
75 Sint32 bErrorFlag = 0;
76 Main& mC64 = Main::Instance();
77 ImageMgr& mImage = mC64.IImageMgr();
78 SpriteMgr& mSprite = mC64.ISpriteMgr();
79 FontMgr& mFont = Main::Instance().IFontMgr();
80 SoundMgr& mSound = Main::Instance().ISoundMgr();
81 MusicMgr& mMusic = Main::Instance().IMusicMgr();
82
83 // Load the fonts
84 if(fntConsole <= 0)
85 {
86 fntConsole = mFont.load(PME_RESOURCES, "console");
87 if(fntConsole < 0)
88 {
89 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the console font.\n");
90 bErrorFlag = 1;
91 }
92 }
93 if(fntInfo <= 0 && bErrorFlag == 0)
94 {
95 fntInfo = mFont.load(PME_RESOURCES, "info");
96 if(fntInfo < 0)
97 {
98 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the info font.\n");
99 bErrorFlag = 1;
100 }
101 }
102 if(fntScore <= 0 && bErrorFlag == 0)
103 {
104 fntScore = mFont.load(PME_RESOURCES, "score");
105 if(fntScore < 0)
106 {
107 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the score font.\n");
108 bErrorFlag = 1;
109 }
110 }
111
112 // Create the menu panel using sprites stored on the CDC
113 if(guiMenu <= 0 && bErrorFlag == 0)
114 {
115 guiMenu = mC64.IGUIMgr().create("menu");
116 if(guiMenu < 0)
117 {
118 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not create the menu panel.\n");
119 bErrorFlag = 1;
120 }
121 else
122 {
123 Panel* myPanel = mC64.IGUIMgr().getPanel(guiMenu);
124 myPanel->baseWidget().setSize(200, 250);
125 myPanel->baseWidget().setPosition(PH_CENTER, PH_CENTERD + 50);
126 myPanel->baseWidget().setBorderWidth(0);
127 myPanel->baseWidget().features(WIDGET_FEATURE_BGDISABLE);
128
129 // Add our buttons
130 myPanel->createWidget("Exit", WT_BUTTON, ID_EXIT);
131 myPanel->getWidget(ID_EXIT)->setKey(SDLK_ESCAPE);
132 myPanel->getWidget(ID_EXIT)->setText("");
133 myPanel->getWidget(ID_EXIT)->setBgSprite(PME_RESOURCES, "widget_exit");
134 myPanel->getWidget(ID_EXIT)->setPosition(PH_CENTER, PH_BOTTOMD);
135
136 myPanel->createWidget("StandardGame", WT_BUTTON, ID_STANDARDGAME);
137 myPanel->getWidget(ID_STANDARDGAME)->setKey(SDLK_s);
138 myPanel->getWidget(ID_STANDARDGAME)->setText("");
139 myPanel->getWidget(ID_STANDARDGAME)->setBgSprite(PME_RESOURCES, "widget_game_standard");
140 myPanel->getWidget(ID_STANDARDGAME)->setPosition(PH_CENTER, PH_TOP);
141
142 myPanel->createWidget("EvolutionGame", WT_BUTTON, ID_EVOLUTIONGAME);
143 myPanel->getWidget(ID_EVOLUTIONGAME)->setKey(SDLK_e);
144 myPanel->getWidget(ID_EVOLUTIONGAME)->setText("");
145 myPanel->getWidget(ID_EVOLUTIONGAME)->setBgSprite(PME_RESOURCES, "widget_game_evolution");
146 myPanel->getWidget(ID_EVOLUTIONGAME)->setPosition(PH_CENTER, PH_TOP + 50);
147
148 #ifdef PME_WORKBENCH_ENABLED
149 myPanel->createWidget("Workbench", WT_BUTTON, ID_WORKBENCHGAME);
150 myPanel->getWidget(ID_WORKBENCHGAME)->setKey(SDLK_w);
151 myPanel->getWidget(ID_WORKBENCHGAME)->setText("");
152 myPanel->getWidget(ID_WORKBENCHGAME)->setBgSprite(PME_RESOURCES, "widget_game_workbench");
153 myPanel->getWidget(ID_WORKBENCHGAME)->setPosition(PH_CENTER, PH_TOP + 100);
154 #endif
155
156 myPanel->createWidget("HoF", WT_BUTTON, ID_HALLOFFAME);
157 myPanel->getWidget(ID_HALLOFFAME)->setKey(SDLK_h);
158 myPanel->getWidget(ID_HALLOFFAME)->setText("");
159 myPanel->getWidget(ID_HALLOFFAME)->setBgSprite(PME_RESOURCES, "widget_hof");
160 #ifdef PME_WORKBENCH_ENABLED
161 myPanel->getWidget(ID_HALLOFFAME)->setPosition(PH_CENTER, PH_TOP + 150);
162 #else
163 myPanel->getWidget(ID_HALLOFFAME)->setPosition(PH_CENTER, PH_TOP + 100);
164 #endif
165 }
166 }
167
168 // Create the game panel using sprites stored on the CDC
169 if(guiGame <= 0 && bErrorFlag == 0)
170 {
171 guiGame = mC64.IGUIMgr().create("game");
172 if(guiGame < 0)
173 {
174 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not create the game panel.\n");
175 bErrorFlag = 1;
176 }
177 else
178 {
179 Panel* myPanel = mC64.IGUIMgr().getPanel(guiGame);
180 myPanel->baseWidget().setSize(300, 250);
181 myPanel->baseWidget().setPosition(PH_CENTER, PH_CENTER);
182 myPanel->baseWidget().setBorderWidth(0);
183 myPanel->baseWidget().features(WIDGET_FEATURE_BGFIT);
184 myPanel->baseWidget().setBgImage(PME_RESOURCES, "messageEnd_bg");
185
186 // Add our buttons
187 myPanel->createWidget("GameLabel", WT_LABEL, ID_GAME_LABEL);
188 myPanel->getWidget(ID_GAME_LABEL)->setFont(get(RM_FONT_SCORE));
189 myPanel->getWidget(ID_GAME_LABEL)->setText("Game Aborted");
190 myPanel->getWidget(ID_GAME_LABEL)->setPosition(PH_CENTER, PH_TOP + 20);
191 myPanel->getWidget(ID_GAME_LABEL)->features(WIDGET_FEATURE_BGDISABLE);
192
193 myPanel->createWidget("GameEnterName", WT_TEXTBOX, ID_GAME_ENTERNAME);
194 myPanel->getWidget(ID_GAME_ENTERNAME)->setSize(200, 48);
195 myPanel->getWidget(ID_GAME_ENTERNAME)->setMargin(5, 20, 0, 20);
196 myPanel->getWidget(ID_GAME_ENTERNAME)->setPosition(PH_CENTER, PH_CENTER);
197 myPanel->getWidget(ID_GAME_ENTERNAME)->setFont(fntInfo);
198 myPanel->getWidget(ID_GAME_ENTERNAME)->setText("PacMan");
199 myPanel->getWidget(ID_GAME_ENTERNAME)->setBgSprite(PME_RESOURCES, "widget_input");
200
201 myPanel->createWidget("GameClose", WT_BUTTON, ID_GAME_CLOSE);
202 myPanel->getWidget(ID_GAME_CLOSE)->setKey(SDLK_RETURN);
203 myPanel->getWidget(ID_GAME_CLOSE)->setText("");
204 myPanel->getWidget(ID_GAME_CLOSE)->setBgSprite(PME_RESOURCES, "widget_close");
205 myPanel->getWidget(ID_GAME_CLOSE)->setPosition(PH_CENTER, PH_BOTTOMD + 25);
206 }
207 }
208
209 // Load the music
210 if(musMenu[0] <= 0 && bErrorFlag == 0)
211 {
212 musMenu[0] = mMusic.load(PME_RESOURCES, "menu_1");
213 if(musMenu[0] < 0)
214 {
215 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the menu_1 music.\n");
216 bErrorFlag = 1;
217 }
218 }
219 if(musMenu[1] <= 0 && bErrorFlag == 0)
220 {
221 musMenu[1] = mMusic.load(PME_RESOURCES, "menu_2");
222 if(musMenu[1] < 0)
223 {
224 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the menu_2 music.\n");
225 bErrorFlag = 1;
226 }
227 }
228 if(musMenu[2] <= 0 && bErrorFlag == 0)
229 {
230 musMenu[2] = mMusic.load(PME_RESOURCES, "menu_3");
231 if(musMenu[2] < 0)
232 {
233 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the menu_3 music.\n");
234 bErrorFlag = 1;
235 }
236 }
237 if(musGame[0] <= 0 && bErrorFlag == 0)
238 {
239 musGame[0] = mMusic.load(PME_RESOURCES, "game_1");
240 if(musGame[0] < 0)
241 {
242 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_1 music.\n");
243 bErrorFlag = 1;
244 }
245 }
246 if(musGame[1] <= 0 && bErrorFlag == 0)
247 {
248 musGame[1] = mMusic.load(PME_RESOURCES, "game_2");
249 if(musGame[1] < 0)
250 {
251 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_2 music.\n");
252 bErrorFlag = 1;
253 }
254 }
255 if(musGame[2] <= 0 && bErrorFlag == 0)
256 {
257 musGame[2] = mMusic.load(PME_RESOURCES, "game_3");
258 if(musGame[2] < 0)
259 {
260 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_3 music.\n");
261 bErrorFlag = 1;
262 }
263 }
264 if(musGame[3] <= 0 && bErrorFlag == 0)
265 {
266 musGame[3] = mMusic.load(PME_RESOURCES, "game_4");
267 if(musGame[3] < 0)
268 {
269 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_4 music.\n");
270 bErrorFlag = 1;
271 }
272 }
273
274 // Load the sounds
275 if(sndThunder <= 0 && bErrorFlag == 0)
276 {
277 sndThunder = mSound.load(PME_RESOURCES, "thunder");
278 if(sndThunder < 0)
279 {
280 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the thunder sound.\n");
281 bErrorFlag = 1;
282 }
283 }
284 if(sndClickOK <= 0 && bErrorFlag == 0)
285 {
286 sndClickOK = mSound.load(PME_RESOURCES, "click_ok");
287 if(sndClickOK < 0)
288 {
289 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the click_ok sound.\n");
290 bErrorFlag = 1;
291 }
292 }
293 if(sndClickCancel <= 0 && bErrorFlag == 0)
294 {
295 sndClickCancel = mSound.load(PME_RESOURCES, "click_cancel");
296 if(sndClickCancel < 0)
297 {
298 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the click_cancel sound.\n");
299 bErrorFlag = 1;
300 }
301 }
302 if(sndClickCancel2 <= 0 && bErrorFlag == 0)
303 {
304 sndClickCancel2 = mSound.load(PME_RESOURCES, "click_cancel2");
305 if(sndClickCancel2 < 0)
306 {
307 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the click_cancel2 sound.\n");
308 bErrorFlag = 1;
309 }
310 }
311 if(sndExit <= 0 && bErrorFlag == 0)
312 {
313 sndExit = mSound.load(PME_RESOURCES, "exit");
314 if(sndExit < 0)
315 {
316 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the exit sound.\n");
317 bErrorFlag = 1;
318 }
319 }
320 if(sndGameAbort <= 0 && bErrorFlag == 0)
321 {
322 sndGameAbort = mSound.load(PME_RESOURCES, "game_abort");
323 if(sndGameAbort < 0)
324 {
325 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_abort sound.\n");
326 bErrorFlag = 1;
327 }
328 }
329 if(sndGameOver <= 0 && bErrorFlag == 0)
330 {
331 sndGameOver = mSound.load(PME_RESOURCES, "game_over");
332 if(sndGameOver < 0)
333 {
334 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_over sound.\n");
335 bErrorFlag = 1;
336 }
337 }
338 if(sndGameStarting <= 0 && bErrorFlag == 0)
339 {
340 sndGameStarting = mSound.load(PME_RESOURCES, "game_starting");
341 if(sndGameStarting < 0)
342 {
343 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_starting sound.\n");
344 bErrorFlag = 1;
345 }
346 }
347 if(sndGamePlayerDeath <= 0 && bErrorFlag == 0)
348 {
349 sndGamePlayerDeath = mSound.load(PME_RESOURCES, "game_player_death");
350 if(sndGamePlayerDeath < 0)
351 {
352 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_player_death sound.\n");
353 bErrorFlag = 1;
354 }
355 }
356 if(sndGameEatPellet <= 0 && bErrorFlag == 0)
357 {
358 sndGameEatPellet = mSound.load(PME_RESOURCES, "game_eat_pellet");
359 if(sndGameEatPellet < 0)
360 {
361 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_eat_pellet sound.\n");
362 bErrorFlag = 1;
363 }
364 }
365 if(sndGameEatPelletPower <= 0 && bErrorFlag == 0)
366 {
367 sndGameEatPelletPower = mSound.load(PME_RESOURCES, "game_eat_pellet_power");
368 if(sndGameEatPelletPower < 0)
369 {
370 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_eat_pellet_power sound.\n");
371 bErrorFlag = 1;
372 }
373 }
374 if(sndGameEatGhost <= 0 && bErrorFlag == 0)
375 {
376 sndGameEatGhost = mSound.load(PME_RESOURCES, "game_player_eat_ghost");
377 if(sndGameEatGhost < 0)
378 {
379 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the game_player_eat_ghost sound.\n");
380 bErrorFlag = 1;
381 }
382 }
383
384 // Load the images
385 if(imgIcon <= 0 && bErrorFlag == 0) // Icon is embedded
386 {
387 imgIcon = mImage.load(pme_icon, pme_icon_size, "PME-icon");
388 if(imgIcon < 0)
389 {
390 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not create the PME Icon.\n");
391 bErrorFlag = 1;
392 }
393 }
394 if(imgMenu <= 0 && bErrorFlag == 0)
395 {
396 imgMenu = mImage.load(PME_RESOURCES, "menu_bg");
397 if(imgMenu < 0)
398 {
399 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the Menu BG.\n");
400 bErrorFlag = 1;
401 }
402 }
403 if(imgHallOfFame <= 0 && bErrorFlag == 0)
404 {
405 imgHallOfFame = mImage.load(PME_RESOURCES, "hof_bg");
406 if(imgHallOfFame < 0)
407 {
408 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the HallOfFame BG.\n");
409 bErrorFlag = 1;
410 }
411 }
412
413 // Load the cursor
414 if(curArrow <= 0 && bErrorFlag == 0)
415 {
416 curArrow = mC64.ICursorMgr().load(PME_RESOURCES, "cursor");
417 if(curArrow < 0)
418 {
419 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the cursor.\n");
420 bErrorFlag = 1;
421 }
422 else
423 {
424 mC64.ICursorMgr().select(curArrow);
425 mC64.ICursorMgr().hide();
426 }
427 }
428
429 // Load the sprites
430 if(sprPacman <= 0 && bErrorFlag == 0)
431 {
432 sprPacman = mSprite.load(PME_RESOURCES, "pacman");
433 if(sprPacman < 0)
434 {
435 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the pacman sprite.\n");
436 bErrorFlag = 1;
437 }
438 }
439 if(sprGhostRed <= 0 && bErrorFlag == 0)
440 {
441 sprGhostRed = mSprite.load(PME_RESOURCES, "ghost_red");
442 if(sprGhostRed < 0)
443 {
444 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the ghost_red sprite.\n");
445 bErrorFlag = 1;
446 }
447 }
448 if(sprGhostPink <= 0 && bErrorFlag == 0)
449 {
450 sprGhostPink = mSprite.load(PME_RESOURCES, "ghost_pink");
451 if(sprGhostPink < 0)
452 {
453 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the ghost_pink sprite.\n");
454 bErrorFlag = 1;
455 }
456 }
457 if(sprGhostBlue <= 0 && bErrorFlag == 0)
458 {
459 sprGhostBlue = mSprite.load(PME_RESOURCES, "ghost_blue");
460 if(sprGhostBlue < 0)
461 {
462 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the ghost_blue sprite.\n");
463 bErrorFlag = 1;
464 }
465 }
466 if(sprGhostOrange <= 0 && bErrorFlag == 0)
467 {
468 sprGhostOrange = mSprite.load(PME_RESOURCES, "ghost_orange");
469 if(sprGhostOrange < 0)
470 {
471 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the ghost_orange sprite.\n");
472 bErrorFlag = 1;
473 }
474 }
475 if(sprPellet <= 0 && bErrorFlag == 0)
476 {
477 sprPellet = mSprite.load(PME_RESOURCES, "pellet");
478 if(sprPellet < 0)
479 {
480 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the pellet sprite.\n");
481 bErrorFlag = 1;
482 }
483 }
484 if(sprPelletPower <= 0 && bErrorFlag == 0)
485 {
486 sprPelletPower = mSprite.load(PME_RESOURCES, "pellet_power");
487 if(sprPelletPower < 0)
488 {
489 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the pellet_power sprite.\n");
490 bErrorFlag = 1;
491 }
492 }
493 if(sprTargets <= 0 && bErrorFlag == 0)
494 {
495 sprTargets = mSprite.load(PME_RESOURCES, "targets");
496 if(sprTargets < 0)
497 {
498 mC64.ILogMgr().get()->msg(LML_CRITICAL, " [ResourceManager] Critical: could not load the targets sprite.\n");
499 bErrorFlag = 1;
500 }
501 }
502
503 // Init our random seed. It is a good place as all the loading stuff will make it more "random"
504 auto hitime = std::chrono::high_resolution_clock::now().time_since_epoch().count();
505 Main::Instance().ITool().randSeedMWC((Sint32)hitime);
506 Main::Instance().ITool().randSeedWELL((Sint32)hitime);
507
508 // Check for any error
509 if(bErrorFlag != 0)
510 {
511 free();
512 return PME_BREAK;
513 }
514
515 return 0;
516}
517
518// Free all resources.
519Sint32 ResourceManager::free()
520{
521 Main& mC64 = Main::Instance();
522
523 if(sprPacman > 0) mC64.ISpriteMgr().close(sprPacman);
524 sprPacman = 0;
525 if(sprGhostRed > 0) mC64.ISpriteMgr().close(sprGhostRed);
526 sprGhostRed = 0;
527 if(sprGhostPink > 0) mC64.ISpriteMgr().close(sprGhostPink);
528 sprGhostPink = 0;
529 if(sprGhostBlue > 0) mC64.ISpriteMgr().close(sprGhostBlue);
530 sprGhostBlue = 0;
531 if(sprGhostOrange > 0) mC64.ISpriteMgr().close(sprGhostOrange);
532 sprGhostOrange = 0;
533 if(sprPellet > 0) mC64.ISpriteMgr().close(sprPellet);
534 sprPellet = 0;
535 if(sprPelletPower > 0) mC64.ISpriteMgr().close(sprPelletPower);
536 sprPelletPower = 0;
537 if(sprTargets > 0) mC64.ISpriteMgr().close(sprTargets);
538 sprTargets = 0;
539
540 if(curArrow > 0) mC64.ICursorMgr().close(curArrow);
541 curArrow = 0;
542
543 if(imgIcon > 0) mC64.IImageMgr().close(imgIcon);
544 imgIcon = 0;
545 if(imgMenu > 0) mC64.IImageMgr().close(imgMenu);
546 imgMenu = 0;
547 if(imgHallOfFame > 0) mC64.IImageMgr().close(imgHallOfFame);
548 imgHallOfFame = 0;
549
550 if(sndThunder > 0) mC64.ISoundMgr().close(sndThunder);
551 sndThunder = 0;
552 if(sndClickOK > 0) mC64.ISoundMgr().close(sndClickOK);
553 sndClickOK = 0;
554 if(sndClickCancel2 > 0) mC64.ISoundMgr().close(sndClickCancel2);
555 sndClickCancel2 = 0;
556 if(sndClickCancel > 0) mC64.ISoundMgr().close(sndClickCancel);
557 sndClickCancel = 0;
558 if(sndExit > 0) mC64.ISoundMgr().close(sndExit);
559 sndExit = 0;
560 if(sndGameAbort > 0) mC64.ISoundMgr().close(sndGameAbort);
561 sndGameAbort = 0;
562 if(sndGameOver > 0) mC64.ISoundMgr().close(sndGameOver);
563 sndGameOver = 0;
564 if(sndGameStarting > 0) mC64.ISoundMgr().close(sndGameStarting);
565 sndGameStarting = 0;
566 if(sndGamePlayerDeath > 0) mC64.ISoundMgr().close(sndGamePlayerDeath);
567 sndGamePlayerDeath = 0;
568 if(sndGameEatPellet > 0) mC64.ISoundMgr().close(sndGameEatPellet);
569 sndGameEatPellet = 0;
570 if(sndGameEatPelletPower > 0) mC64.ISoundMgr().close(sndGameEatPelletPower);
571 sndGameEatPelletPower = 0;
572 if(sndGameEatGhost > 0) mC64.ISoundMgr().close(sndGameEatGhost);
573 sndGameEatGhost = 0;
574
575 if(musMenu[0] > 0) mC64.IMusicMgr().close(musMenu[0]);
576 musMenu[0] = 0;
577 if(musMenu[1] > 0) mC64.IMusicMgr().close(musMenu[1]);
578 musMenu[1] = 0;
579 if(musMenu[2] > 0) mC64.IMusicMgr().close(musMenu[2]);
580 musMenu[2] = 0;
581 if(musGame[0] > 0) mC64.IMusicMgr().close(musGame[0]);
582 musGame[0] = 0;
583 if(musGame[1] > 0) mC64.IMusicMgr().close(musGame[1]);
584 musGame[1] = 0;
585 if(musGame[2] > 0) mC64.IMusicMgr().close(musGame[2]);
586 musGame[2] = 0;
587 if(musGame[3] > 0) mC64.IMusicMgr().close(musGame[3]);
588 musGame[3] = 0;
589
590 if(fntConsole > 0) mC64.IFontMgr().close(fntConsole);
591 fntConsole = 0;
592 if(fntInfo > 0) mC64.IFontMgr().close(fntInfo);
593 fntInfo = 0;
594 if(fntScore > 0) mC64.IFontMgr().close(fntScore);
595 fntScore = 0;
596
597 if(guiMenu > 0) mC64.IGUIMgr().close(guiMenu);
598 guiMenu = 0;
599
600 if(guiGame > 0) mC64.IGUIMgr().close(guiGame);
601 guiGame = 0;
602 return 0;
603}
604
605// Get resources which are created with load()
606Sint32 ResourceManager::get(Sint32 iID) const
607{
608 SpriteMgr& mSprite = Main::Instance().ISpriteMgr();
609 Sint32 iTmp;
610
611 switch(iID)
612 {
613 case RM_PANEL_MENU: return guiMenu;
614 case RM_PANEL_GAME: return guiGame;
615
616 case RM_FONT_CONSOLE: return fntConsole;
617 case RM_FONT_INFO: return fntInfo;
618 case RM_FONT_SCORE: return fntScore;
619
620 case RM_MUS_MENU: return musMenu[Main::Instance().ITool().randMWC() % 3];
621 case RM_MUS_GAME: return musGame[Main::Instance().ITool().randMWC() % 4];
622
623 case RM_SND_THUNDER: return sndThunder;
624 case RM_SND_CLICKOK: return sndClickOK;
625 case RM_SND_CLICKCANCEL: return sndClickCancel;
626 case RM_SND_CLICKCANCEL2: return sndClickCancel2;
627 case RM_SND_EXIT: return sndExit;
628 case RM_SND_GAMEABORT: return sndGameAbort;
629 case RM_SND_GAMEOVER: return sndGameOver;
630 case RM_SND_GAMESTARTING: return sndGameStarting;
631 case RM_SND_GAMEPLAYERDEATH: return sndGamePlayerDeath;
632 case RM_SND_GAMEEATPELLET: return sndGameEatPellet;
633 case RM_SND_GAMEEATPELLETPOWER: return sndGameEatPelletPower;
634 case RM_SND_GAMEEATGHOST: return sndGameEatGhost;
635
636 case RM_IMG_ICON: return imgIcon;
637 case RM_IMG_MENU: return imgMenu;
638 case RM_IMG_HOF: return imgHallOfFame;
639
640 case RM_SPR_PACMAN:
641 {
642 iTmp = mSprite.child(sprPacman);
643 Sprite* pSpr = mSprite.get(sprPacman);
644 if(bPacManDeathAnim == 0) pSpr->setAnimRange(SPR_STATE_NORMAL, 10, 12); // Disable PacMan death animation
645 else pSpr->setAnimRange(SPR_STATE_NORMAL, 0, 12); // Enable PacMan death animation
646 return iTmp;
647 }
648 case RM_SPR_GHOSTRED: return mSprite.child(sprGhostRed);
649 case RM_SPR_GHOSTPINK: return mSprite.child(sprGhostPink);
650 case RM_SPR_GHOSTBLUE: return mSprite.child(sprGhostBlue);
651 case RM_SPR_GHOSTORANGE: return mSprite.child(sprGhostOrange);
652 case RM_SPR_PELLET: return sprPellet;
653 case RM_SPR_PELLETPOWER: return mSprite.child(sprPelletPower);
654 case RM_SPR_TARGETS: return mSprite.child(sprTargets);
655
656 default: return PME_BREAK;
657 }
658}
659
660Sint32 ResourceManager::setPacManDeathAnim(Sint32 bFlag)
661{
662 if(bFlag <= 0) bPacManDeathAnim = 0;
663 else bPacManDeathAnim = 1;
664 return 0;
665}