]> git.mxchange.org Git - quix0rs-blobwars.git/blob - src/resources.cpp
Use time_t to store time data.
[quix0rs-blobwars.git] / src / resources.cpp
1 /*
2 Copyright (C) 2004-2011 Parallel Realities
3 Copyright (C) 2011-2015 Perpendicular Dimensions
4
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 See the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 */
21
22 #include "resources.h"
23
24 void loadSound(int index, const char *filename)
25 {
26         audio.loadSound(index, 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");
103         loadSound(SND_WATEROUT, "sound/waterOut");
104         loadSound(SND_ITEM, "sound/item");
105         loadSound(SND_PISTOL, "sound/pistol");
106         loadSound(SND_RICO1, "sound/rico1");
107         loadSound(SND_RICO2, "sound/rico2");
108         loadSound(SND_MACHINEGUN, "sound/machinegun");
109         loadSound(SND_DEATH1, "sound/death1");
110         loadSound(SND_DEATH2, "sound/death2");
111         loadSound(SND_DEATH3, "sound/death3");
112         loadSound(SND_GRENADE, "sound/grenade");
113         loadSound(SND_ROCKET, "sound/rocket");
114         loadSound(SND_FIREBALL, "sound/fireball");
115         loadSound(SND_HIT, "sound/punch");
116         loadSound(SND_SPLAT, "sound/splat");
117         loadSound(SND_POP, "sound/pop1");
118         loadSound(SND_TELEPORT1, "sound/teleport1");
119         loadSound(SND_TELEPORT2, "sound/teleport2");
120         loadSound(SND_TELEPORT3, "sound/teleport3");
121         loadSound(SND_GETWEAPON, "sound/weaponPickup");
122         loadSound(SND_LASER, "sound/laser");
123         loadSound(SND_ELECDEATH1, "sound/elecDeath1");
124         loadSound(SND_ELECDEATH2, "sound/elecDeath2");
125         loadSound(SND_ELECDEATH3, "sound/elecDeath3");
126         loadSound(SND_LOCKEDDOOR, "sound/doorLocked");
127         loadSound(SND_OPENDOOR, "sound/doorOpen");
128         loadSound(SND_DOOROPENED, "sound/doorOpened");
129         loadSound(SND_SWITCH1, "sound/switch");
130         loadSound(SND_SWITCH2, "sound/switch");
131         loadSound(SND_DROWNING, "sound/drowning");
132         loadSound(SND_GULP, "sound/gulp");
133         loadSound(SND_EAT, "sound/eat");
134         loadSound(SND_THROW, "sound/throw");
135         loadSound(SND_GRBOUNCE, "sound/grenadeBounce");
136         loadSound(SND_SPREADGUN, "sound/plasma");
137         loadSound(SND_STONEBREAK, "sound/stoneBreak");
138         loadSound(SND_ELECTRICITY1, "sound/electricity1");
139         loadSound(SND_ELECTRICITY2, "sound/electricity2");
140         loadSound(SND_ELECTRICITY3, "sound/electricity3");
141         loadSound(SND_CLANG, "sound/clang");
142         loadSound(SND_FIRECRACKLE, "sound/fireCrackle");
143         loadSound(SND_CLOCK, "sound/clock");
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 }