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