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