Just fixed two small bugs in the gameplay during pause:
[supertux.git] / src / resources.cpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  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 #include "globals.h"
21 #include "scene.h"
22 #include "player.h"
23 #include "badguy.h"
24 #include "gameobjs.h"
25 #include "special.h"
26 #include "resources.h"
27 #include "sprite_manager.h"
28 #include "setup.h"
29
30 Surface* img_waves[3]; 
31 Surface* img_water;
32 Surface* img_pole;
33 Surface* img_poletop;
34 Surface* img_flag[2];
35 Surface* img_cloud[2][4];
36
37 Surface* img_red_glow;
38
39 SpriteManager* sprite_manager = 0;
40
41 /* Load graphics/sounds shared between all levels: */
42 void loadshared()
43 {
44   int i;
45
46   sprite_manager = new SpriteManager(datadir + "/supertux.strf");
47
48   /* Tuxes: */
49   largetux_stand_left  = sprite_manager->load("largetux-stand-left");
50   largetux_stand_right = sprite_manager->load("largetux-stand-right");
51
52   smalltux_gameover = sprite_manager->load("smalltux-gameover");
53
54   smalltux_skid_left  = sprite_manager->load("smalltux-skid-left");
55   smalltux_skid_right = sprite_manager->load("smalltux-skid-right");
56
57   smalltux_stand_left = new Surface(datadir + "/images/shared/smalltux-left-6.png", USE_ALPHA);
58   smalltux_stand_right = new Surface(datadir + "/images/shared/smalltux-right-6.png", USE_ALPHA);
59
60   smalltux_jump_left = new Surface(datadir + "/images/shared/smalltux-jump-left.png", USE_ALPHA);
61   smalltux_jump_right = new Surface(datadir + "/images/shared/smalltux-jump-right.png", USE_ALPHA);
62
63   tux_right.resize(8);
64   tux_right[0] = new Surface(datadir + "/images/shared/smalltux-right-1.png", USE_ALPHA);
65   tux_right[1] = new Surface(datadir + "/images/shared/smalltux-right-2.png", USE_ALPHA);
66   tux_right[2] = new Surface(datadir + "/images/shared/smalltux-right-3.png", USE_ALPHA);
67   tux_right[3] = new Surface(datadir + "/images/shared/smalltux-right-4.png", USE_ALPHA);
68   tux_right[4] = new Surface(datadir + "/images/shared/smalltux-right-5.png", USE_ALPHA);
69   tux_right[5] = new Surface(datadir + "/images/shared/smalltux-right-6.png", USE_ALPHA);
70   tux_right[6] = new Surface(datadir + "/images/shared/smalltux-right-7.png", USE_ALPHA);
71   tux_right[7] = new Surface(datadir + "/images/shared/smalltux-right-8.png", USE_ALPHA);
72
73   tux_left.resize(8);
74   tux_left[0] = new Surface(datadir + "/images/shared/smalltux-left-1.png", USE_ALPHA);
75   tux_left[1] = new Surface(datadir + "/images/shared/smalltux-left-2.png", USE_ALPHA);
76   tux_left[2] = new Surface(datadir + "/images/shared/smalltux-left-3.png", USE_ALPHA);
77   tux_left[3] = new Surface(datadir + "/images/shared/smalltux-left-4.png", USE_ALPHA);
78   tux_left[4] = new Surface(datadir + "/images/shared/smalltux-left-5.png", USE_ALPHA);
79   tux_left[5] = new Surface(datadir + "/images/shared/smalltux-left-6.png", USE_ALPHA);
80   tux_left[6] = new Surface(datadir + "/images/shared/smalltux-left-7.png", USE_ALPHA);
81   tux_left[7] = new Surface(datadir + "/images/shared/smalltux-left-8.png", USE_ALPHA);
82
83   firetux_right[0] = new Surface(datadir + "/images/shared/firetux-right-0.png", USE_ALPHA);
84   firetux_right[1] = new Surface(datadir + "/images/shared/firetux-right-1.png", USE_ALPHA);
85   firetux_right[2] = new Surface(datadir + "/images/shared/firetux-right-2.png", USE_ALPHA);
86
87   firetux_left[0] = new Surface(datadir + "/images/shared/firetux-left-0.png", USE_ALPHA);
88   firetux_left[1] = new Surface(datadir + "/images/shared/firetux-left-1.png", USE_ALPHA);
89   firetux_left[2] = new Surface(datadir + "/images/shared/firetux-left-2.png", USE_ALPHA);
90
91
92   cape_right[0] = new Surface(datadir + "/images/shared/cape-right-0.png",
93                USE_ALPHA);
94
95   cape_right[1] = new Surface(datadir + "/images/shared/cape-right-1.png",
96                USE_ALPHA);
97
98   cape_left[0] = new Surface(datadir + "/images/shared/cape-left-0.png",
99                USE_ALPHA);
100
101   cape_left[1] = new Surface(datadir + "/images/shared/cape-left-1.png",
102                USE_ALPHA);
103
104   bigtux_right = sprite_manager->load("largetux-walk-right");
105   bigtux_left  = sprite_manager->load("largetux-walk-left");
106
107   bigtux_left_jump  = sprite_manager->load("largetux-jump-left");
108   bigtux_right_jump = sprite_manager->load("largetux-jump-right");
109
110   bigcape_right[0] = new Surface(datadir + "/images/shared/bigcape-right-0.png",
111                USE_ALPHA);
112
113   bigcape_right[1] = new Surface(datadir + "/images/shared/bigcape-right-1.png",
114                USE_ALPHA);
115
116   bigcape_left[0] = new Surface(datadir + "/images/shared/bigcape-left-0.png",
117                USE_ALPHA);
118
119   bigcape_left[1] = new Surface(datadir + "/images/shared/bigcape-left-1.png",
120                USE_ALPHA);
121
122   bigfiretux_right[0] = new Surface(datadir + "/images/shared/bigfiretux-right-0.png",
123                USE_ALPHA);
124
125   bigfiretux_right[1] = new Surface(datadir + "/images/shared/bigfiretux-right-1.png",
126                USE_ALPHA);
127
128   bigfiretux_right[2] = new Surface(datadir + "/images/shared/bigfiretux-right-2.png",
129                USE_ALPHA);
130
131   bigfiretux_right_jump = new Surface(datadir + "/images/shared/bigfiretux-right-jump.png", USE_ALPHA);
132
133   bigfiretux_left[0] = new Surface(datadir + "/images/shared/bigfiretux-left-0.png",
134                USE_ALPHA);
135
136   bigfiretux_left[1] = new Surface(datadir + "/images/shared/bigfiretux-left-1.png",
137                USE_ALPHA);
138
139   bigfiretux_left[2] = new Surface(datadir + "/images/shared/bigfiretux-left-2.png",
140                USE_ALPHA);
141
142   bigfiretux_left_jump = new Surface(datadir + "/images/shared/bigfiretux-left-jump.png", USE_ALPHA);
143
144   bigcape_right[0] = new Surface(datadir + "/images/shared/bigcape-right-0.png",
145                USE_ALPHA);
146
147   bigcape_right[1] = new Surface(datadir + "/images/shared/bigcape-right-1.png",
148                USE_ALPHA);
149
150   bigcape_left[0] = new Surface(datadir + "/images/shared/bigcape-left-0.png",
151                USE_ALPHA);
152
153   bigcape_left[1] = new Surface(datadir + "/images/shared/bigcape-left-1.png",
154                USE_ALPHA);
155
156
157   ducktux_left  = sprite_manager->load("largetux-duck-left");
158   ducktux_right = sprite_manager->load("largetux-duck-right");
159
160   skidtux_right = new Surface(datadir +
161                "/images/shared/largetux-skid-right.png",
162                USE_ALPHA);
163
164   skidtux_left = new Surface(datadir +
165                "/images/shared/largetux-skid-left.png",
166                USE_ALPHA);
167
168   duckfiretux_right = new Surface(datadir +
169                "/images/shared/duckfiretux-right.png",
170                USE_ALPHA);
171
172   duckfiretux_left = new Surface(datadir +
173                "/images/shared/duckfiretux-left.png",
174                USE_ALPHA);
175
176   skidfiretux_right = new Surface(datadir +
177                "/images/shared/skidfiretux-right.png",
178                USE_ALPHA);
179
180   skidfiretux_left = new Surface(datadir +
181                "/images/shared/skidfiretux-left.png",
182                USE_ALPHA);
183
184
185   /* Water: */
186
187
188   img_water = new Surface(datadir + "/images/shared/water.png", IGNORE_ALPHA);
189
190   img_waves[0] = new Surface(datadir + "/images/shared/waves-0.png",
191                USE_ALPHA);
192
193   img_waves[1] = new Surface(datadir + "/images/shared/waves-1.png",
194                USE_ALPHA);
195
196   img_waves[2] = new Surface(datadir + "/images/shared/waves-2.png",
197                USE_ALPHA);
198
199
200   /* Pole: */
201
202   img_pole = new Surface(datadir + "/images/shared/pole.png", USE_ALPHA);
203   img_poletop = new Surface(datadir + "/images/shared/poletop.png",
204                USE_ALPHA);
205
206
207   /* Flag: */
208
209   img_flag[0] = new Surface(datadir + "/images/shared/flag-0.png",
210                USE_ALPHA);
211   img_flag[1] = new Surface(datadir + "/images/shared/flag-1.png",
212                USE_ALPHA);
213
214
215   /* Cloud: */
216
217   img_cloud[0][0] = new Surface(datadir + "/images/shared/cloud-00.png",
218                USE_ALPHA);
219
220   img_cloud[0][1] = new Surface(datadir + "/images/shared/cloud-01.png",
221                USE_ALPHA);
222
223   img_cloud[0][2] = new Surface(datadir + "/images/shared/cloud-02.png",
224                USE_ALPHA);
225
226   img_cloud[0][3] = new Surface(datadir + "/images/shared/cloud-03.png",
227                USE_ALPHA);
228
229
230   img_cloud[1][0] = new Surface(datadir + "/images/shared/cloud-10.png",
231                USE_ALPHA);
232
233   img_cloud[1][1] = new Surface(datadir + "/images/shared/cloud-11.png",
234                USE_ALPHA);
235
236   img_cloud[1][2] = new Surface(datadir + "/images/shared/cloud-12.png",
237                USE_ALPHA);
238
239   img_cloud[1][3] = new Surface(datadir + "/images/shared/cloud-13.png",
240                USE_ALPHA);
241
242
243   /* Bad guys: */
244   load_badguy_gfx();
245
246   /* Upgrades: */
247   load_special_gfx();
248
249   /* Weapons: */
250   img_red_glow = new Surface(datadir + "/images/shared/red-glow.png",
251                USE_ALPHA);
252
253   /* Distros: */
254   img_distro[0] = new Surface(datadir + "/images/shared/distro-0.png",
255                USE_ALPHA);
256
257   img_distro[1] = new Surface(datadir + "/images/shared/distro-1.png",
258                USE_ALPHA);
259
260   img_distro[2] = new Surface(datadir + "/images/shared/distro-2.png",
261                USE_ALPHA);
262
263   img_distro[3] = new Surface(datadir + "/images/shared/distro-3.png",
264                USE_ALPHA);
265
266
267   /* Tux life: */
268
269   tux_life = new Surface(datadir + "/images/shared/tux-life.png",
270                          USE_ALPHA);
271
272   /* Sound effects: */
273
274   /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
275                     // initialize sounds[i] with the correct pointer's value:
276                     // NULL or something else. And it will be dangerous to
277                     // play with not-initialized pointers.
278                     // This is also true with if (use_music)
279                     Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
280   */
281   for (i = 0; i < NUM_SOUNDS; i++)
282     sounds[i] = load_sound(datadir + soundfilenames[i]);
283
284   /* Herring song */
285   herring_song = load_song(datadir + "/music/SALCON.MOD");
286   if(!herring_song)
287     st_abort("Couldn't load song ", "/music/SALCON.MOD");
288 }
289
290
291 /* Free shared data: */
292 void unloadshared(void)
293 {
294   delete sprite_manager;
295
296   int i;
297
298   free_special_gfx();
299
300   delete smalltux_gameover;
301
302   for (i = 0; i < 3; i++)
303     {
304       delete tux_right[i];
305       delete tux_left[i];
306     }
307
308   delete bigtux_right_jump;
309   delete bigtux_left_jump;
310
311   for (i = 0; i < 2; i++)
312     {
313       delete cape_right[i];
314       delete cape_left[i];
315       delete bigcape_right[i];
316       delete bigcape_left[i];
317     }
318
319   delete ducktux_left;
320   delete ducktux_right;
321
322   delete skidtux_left;
323   delete skidtux_right;
324
325   free_badguy_gfx();
326
327   delete img_water;
328   for (i = 0; i < 3; i++)
329     delete img_waves[i];
330
331   delete img_pole;
332   delete img_poletop;
333
334   for (i = 0; i < 2; i++)
335     delete img_flag[i];
336
337   for (i = 0; i < 4; i++)
338     {
339       delete img_distro[i];
340       delete img_cloud[0][i];
341       delete img_cloud[1][i];
342     }
343
344   for (i = 0; i < NUM_SOUNDS; i++)
345     free_chunk(sounds[i]);
346
347   /* free the herring song */
348   free_music( herring_song );
349 }
350
351 /* EOF */