1 #include "Resources.h"
2
Resources(FileUtility * fileUtility,SoundManager * sndManager)3 violetland::Resources::Resources(FileUtility* fileUtility,
4 SoundManager* sndManager) {
5 m_fileUtil = fileUtility;
6 m_sndManager = sndManager;
7
8 ExplSounds.push_back(loadSnd("explode-0.ogg"));
9 ExplSounds.push_back(loadSnd("explode-1.ogg"));
10 PlayerDeathSound = loadSnd("player_killed.ogg");
11
12 PlayerHitSounds.push_back(loadSnd("player_hit_0.ogg"));
13 PlayerHitSounds.push_back(loadSnd("player_hit_1.ogg"));
14 PlayerHitSounds.push_back(loadSnd("player_hit_2.ogg"));
15
16 PlayerWalkSprite = loadSprite(25, "player/walk/%i.png");
17 PlayerDeathSprites.push_back(loadSprite(56, "player/death/0/%i.png"));
18 PlayerDeathSprites.push_back(loadSprite(42, "player/death/1/%i.png"));
19
20 GrenadeSprite = loadSprite(12, "grenade/%i.png");
21
22 ExplTex.push_back(loadTex("expl_0.png"));
23 ExplTex.push_back(loadTex("expl_1.png"));
24
25 BloodTex.push_back(loadTex("blood_0.png"));
26 BloodTex.push_back(loadTex("blood_1.png"));
27 BloodTex.push_back(loadTex("blood_2.png"));
28
29 Crystal = new StaticObject(0, 0, 128, 128, loadTex("crystal.png"), true);
30
31 HealthIndicator = new StaticObject(0, 0, 128, 128, loadTex("health.png"),
32 true);
33 LevelUpIndicator = new StaticObject(0, 0, 128, 128, loadTex("levelup.png"),
34 true);
35
36 loadPowerupTex(BONUS_MEDIKIT, "medikit.png");
37 loadPowerupTex(BONUS_GRENADES, "grenade.png");
38 loadPowerupTex(BONUS_FREEZE, "freeze.png");
39 loadPowerupTex(BONUS_PENBULLETS, "penbullets.png");
40 loadPowerupTex(BONUS_NUKE, "bon_nuke.png");
41 loadPowerupTex(BONUS_AGILITYROIDS, "pill.png");
42 loadPowerupTex(BONUS_VITALITYROIDS, "pill.png");
43 loadPowerupTex(BONUS_STRENGTHROIDS, "pill.png");
44 loadPowerupTex(BONUS_TELEPORTS, "teleport.png");
45 }
46
loadSprite(unsigned int frames,std::string pattern)47 Sprite* violetland::Resources::loadSprite(unsigned int frames,
48 std::string pattern) {
49 std::vector<SDL_Surface*> animSurfaces;
50 for (unsigned i = 0; i < frames; i++) {
51 std::ostringstream oss;
52 oss << boost::format(pattern) % i;
53 SDL_Surface *surface = ImageUtility::loadImage(m_fileUtil->getFullPath(
54 FileUtility::anima, oss.str()));
55 animSurfaces.push_back(surface);
56 }
57 return new Sprite(animSurfaces);
58 }
59
loadSnd(std::string fileName)60 Sound* violetland::Resources::loadSnd(std::string fileName) {
61 return m_sndManager->create(m_fileUtil->getFullPath(FileUtility::sound,
62 fileName));
63 }
64
loadTex(std::string fileName)65 Texture* violetland::Resources::loadTex(std::string fileName) {
66 return new Texture(ImageUtility::loadImage(m_fileUtil->getFullPath(
67 FileUtility::image, fileName)), GL_TEXTURE_2D, GL_LINEAR, true);
68 }
69
loadPowerupTex(BonusType type,std::string fileName)70 void violetland::Resources::loadPowerupTex(BonusType type,
71 std::string fileName) {
72 PowerupTex.insert(std::map<BonusType, Texture*>::value_type(type,
73 new Texture(ImageUtility::loadImage(m_fileUtil->getFullPath(
74 FileUtility::image, fileName)), GL_TEXTURE_2D, GL_LINEAR,
75 true)));
76 }
77
~Resources()78 violetland::Resources::~Resources() {
79 delete HealthIndicator;
80 delete LevelUpIndicator;
81 delete Crystal;
82 delete PlayerDeathSound;
83 delete PlayerWalkSprite;
84 delete GrenadeSprite;
85
86 clearVector<Texture*> (&ExplTex);
87 clearVector<Texture*> (&BloodTex);
88 clearVector<Sound*> (&ExplSounds);
89 clearVector<Sound*> (&PlayerHitSounds);
90 clearVector<Sprite*> (&PlayerDeathSprites);
91 clearMap<BonusType, Texture*> (&PowerupTex);
92 }
93