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