]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/resources.cpp
Ensure the map editor can be compiled.
[quix0rs-blobwars.git] / src / resources.cpp
1 /*
2 Copyright (C) 2004 Parallel Realities
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "resources.h"
22
23 void loadSound(int index, const char *filename)
24 {
25         if (!audio.loadSound(index, filename))
26                 graphics.showErrorAndExit(ERR_FILE, filename);
27
28         graphics.showLoading(1, 30);
29 }
30
31 void loadSprite(const char *token)
32 {
33         Sprite *sprite;
34
35         char name[50];
36         char filename[8][100];
37         int frameTime[8];
38
39         int i;
40         int hue, sat, val;
41
42         sscanf(token, "%s %d %d %d %s %d %s %d %s %d %s %d %s %d %s %d %s %d %s %d", name, &hue, &sat, &val, filename[0], &frameTime[0], filename[1], &frameTime[1], filename[2], &frameTime[2], filename[3], &frameTime[3], filename[4], &frameTime[4], filename[5], &frameTime[5], filename[6], &frameTime[6], filename[7], &frameTime[7]);
43
44         sprite = graphics.addSprite(name);
45
46         i = 0;
47
48         while (true)
49         {
50                 if (strcmp(filename[i], "@none@") == 0)
51                         break;
52
53                 sprite->setFrame(i, graphics.loadImage(filename[i], hue, sat, val), frameTime[i]);
54
55                 i++;
56                 
57                 if (i == 8)
58                         break;
59         }
60 }
61
62 void loadResources()
63 {
64         graphics.resetLoading();
65
66         audio.free();
67         graphics.free();
68         
69         graphics.quickSprite("cheatHeader", graphics.loadImage("gfx/main/cheats.png"));
70         graphics.quickSprite("optionsHeader", graphics.loadImage("gfx/main/options.png"));
71         graphics.quickSprite("joystickHeader", graphics.loadImage("gfx/main/joystickConfig.png"));
72         graphics.quickSprite("keyHeader", graphics.loadImage("gfx/main/keyConfig.png"));
73         graphics.quickSprite("optionsBackground", graphics.loadImage("gfx/main/optionsBackground.png"));
74
75         SDL_FillRect(graphics.screen, NULL, graphics.black);
76         graphics.drawString(_("Loading..."), 320, 440, TXT_CENTERED, graphics.screen);
77         graphics.showLoading(0, 0);
78         graphics.updateScreen();
79         
80         if (!engine.loadDefines())
81                 graphics.showErrorAndExit("Could not load map define list '%s'", "data/defines.h");
82
83         if (!engine.loadData("data/mainSprites"))
84                 graphics.showErrorAndExit(ERR_FILE, "data/mainSprites");
85
86         char *token = strtok((char*)engine.dataBuffer, "\n");
87
88         while (true)
89         {
90                 if (strcmp(token, "@EOF@") == 0)
91                 {
92                         break;
93                 }
94
95                 loadSprite(token);
96
97                 token = strtok(NULL, "\n");
98
99                 graphics.showLoading(1, 20);
100         }
101
102         loadSound(SND_WATERIN, "sound/waterIn.wav");
103         loadSound(SND_WATEROUT, "sound/waterOut.wav");
104         loadSound(SND_ITEM, "sound/item.wav");
105         loadSound(SND_PISTOL, "sound/pistol.wav");
106         loadSound(SND_RICO1, "sound/rico1.wav");
107         loadSound(SND_RICO2, "sound/rico2.wav");
108         loadSound(SND_MACHINEGUN, "sound/machinegun.wav");
109         loadSound(SND_DEATH1, "sound/death1.wav");
110         loadSound(SND_DEATH2, "sound/death2.wav");
111         loadSound(SND_DEATH3, "sound/death3.wav");
112         loadSound(SND_GRENADE, "sound/grenade.wav");
113         loadSound(SND_ROCKET, "sound/rocket.wav");
114         loadSound(SND_FIREBALL, "sound/fireball.wav");
115         loadSound(SND_HIT, "sound/punch.wav");
116         loadSound(SND_SPLAT, "sound/splat.wav");
117         loadSound(SND_POP, "sound/pop1.wav");
118         loadSound(SND_TELEPORT1, "sound/teleport1.wav");
119         loadSound(SND_TELEPORT2, "sound/teleport2.wav");
120         loadSound(SND_TELEPORT3, "sound/teleport3.wav");
121         loadSound(SND_GETWEAPON, "sound/weaponPickup.wav");
122         loadSound(SND_LASER, "sound/laser.wav");
123         loadSound(SND_ELECDEATH1, "sound/elecDeath1.wav");
124         loadSound(SND_ELECDEATH2, "sound/elecDeath2.wav");
125         loadSound(SND_ELECDEATH3, "sound/elecDeath3.wav");
126         loadSound(SND_LOCKEDDOOR, "sound/doorLocked.wav");
127         loadSound(SND_OPENDOOR, "sound/doorOpen.wav");
128         loadSound(SND_DOOROPENED, "sound/doorOpened.wav");
129         loadSound(SND_SWITCH1, "sound/switch.wav");
130         loadSound(SND_SWITCH2, "sound/switch.wav");
131         loadSound(SND_DROWNING, "sound/drowning.wav");
132         loadSound(SND_GULP, "sound/gulp.wav");
133         loadSound(SND_EAT, "sound/eat.wav");
134         loadSound(SND_THROW, "sound/throw.wav");
135         loadSound(SND_GRBOUNCE, "sound/grenadeBounce.wav");
136         loadSound(SND_SPREADGUN, "sound/plasma.wav");
137         loadSound(SND_STONEBREAK, "sound/stoneBreak.wav");
138         loadSound(SND_ELECTRICITY1, "sound/electricity1.wav");
139         loadSound(SND_ELECTRICITY2, "sound/electricity2.wav");
140         loadSound(SND_ELECTRICITY3, "sound/electricity3.wav");
141         loadSound(SND_CLANG, "sound/clang.wav");
142         loadSound(SND_FIRECRACKLE, "sound/fireCrackle.wav");
143         loadSound(SND_CLOCK, "sound/clock.wav");
144
145         loadDefWeapons();
146
147         graphics.showLoading(35, 35);
148
149         loadDefEnemies();
150
151         graphics.showLoading(40, 40);
152
153         loadDefItems();
154         
155         graphics.showLoading(45, 45);
156
157         graphics.loadMapTiles("gfx/common");
158
159         player.setSprites(graphics.getSprite("BobRight", true), graphics.getSprite("BobLeft", true), graphics.getSprite("BobSpin", true));
160
161         graphics.showLoading(50, 50);
162
163         loadMapData(game.mapName);
164
165         graphics.showLoading(100, 100);
166
167         #if USEPAK
168         graphics.showLoading(100, 100);
169         graphics.delay(100);
170         #endif
171
172         createBoss(game.stageName);
173         
174         game.canContinue = 0;
175
176         // We don't need this anymore. Remove it to free up some memory...
177         engine.defineList.clear();
178 }