- fixed problem with last_menu not being able to handle menues deeper than two submenues
[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 = sprite_manager->load("largetux-walk-right");
79   bigtux_left  = sprite_manager->load("largetux-walk-left");
80
81   bigtux_left_jump  = sprite_manager->load("largetux-jump-left");
82   bigtux_right_jump = sprite_manager->load("largetux-jump-right");
83
84   bigcape_right[0] = new Surface(datadir + "/images/shared/bigcape-right-0.png",
85                USE_ALPHA);
86
87   bigcape_right[1] = new Surface(datadir + "/images/shared/bigcape-right-1.png",
88                USE_ALPHA);
89
90   bigcape_left[0] = new Surface(datadir + "/images/shared/bigcape-left-0.png",
91                USE_ALPHA);
92
93   bigcape_left[1] = new Surface(datadir + "/images/shared/bigcape-left-1.png",
94                USE_ALPHA);
95
96   bigfiretux_right[0] = new Surface(datadir + "/images/shared/bigfiretux-right-0.png",
97                USE_ALPHA);
98
99   bigfiretux_right[1] = new Surface(datadir + "/images/shared/bigfiretux-right-1.png",
100                USE_ALPHA);
101
102   bigfiretux_right[2] = new Surface(datadir + "/images/shared/bigfiretux-right-2.png",
103                USE_ALPHA);
104
105   bigfiretux_right_jump = new Surface(datadir + "/images/shared/bigfiretux-right-jump.png", USE_ALPHA);
106
107   bigfiretux_left[0] = new Surface(datadir + "/images/shared/bigfiretux-left-0.png",
108                USE_ALPHA);
109
110   bigfiretux_left[1] = new Surface(datadir + "/images/shared/bigfiretux-left-1.png",
111                USE_ALPHA);
112
113   bigfiretux_left[2] = new Surface(datadir + "/images/shared/bigfiretux-left-2.png",
114                USE_ALPHA);
115
116   bigfiretux_left_jump = new Surface(datadir + "/images/shared/bigfiretux-left-jump.png", USE_ALPHA);
117
118   bigcape_right[0] = new Surface(datadir + "/images/shared/bigcape-right-0.png",
119                USE_ALPHA);
120
121   bigcape_right[1] = new Surface(datadir + "/images/shared/bigcape-right-1.png",
122                USE_ALPHA);
123
124   bigcape_left[0] = new Surface(datadir + "/images/shared/bigcape-left-0.png",
125                USE_ALPHA);
126
127   bigcape_left[1] = new Surface(datadir + "/images/shared/bigcape-left-1.png",
128                USE_ALPHA);
129
130
131   ducktux_left  = sprite_manager->load("largetux-duck-left");
132   ducktux_right = sprite_manager->load("largetux-duck-right");
133
134   skidtux_right = new Surface(datadir +
135                "/images/shared/skidtux-right.png",
136                USE_ALPHA);
137
138   skidtux_left = new Surface(datadir +
139                "/images/shared/skidtux-left.png",
140                USE_ALPHA);
141
142   duckfiretux_right = new Surface(datadir +
143                "/images/shared/duckfiretux-right.png",
144                USE_ALPHA);
145
146   duckfiretux_left = new Surface(datadir +
147                "/images/shared/duckfiretux-left.png",
148                USE_ALPHA);
149
150   skidfiretux_right = new Surface(datadir +
151                "/images/shared/skidfiretux-right.png",
152                USE_ALPHA);
153
154   skidfiretux_left = new Surface(datadir +
155                "/images/shared/skidfiretux-left.png",
156                USE_ALPHA);
157
158
159   /* Boxes: */
160
161   img_box_full = new Surface(datadir + "/images/shared/box-full.png",
162                IGNORE_ALPHA);
163   img_box_empty = new Surface(datadir + "/images/shared/box-empty.png",
164                IGNORE_ALPHA);
165
166
167   /* Water: */
168
169
170   img_water = new Surface(datadir + "/images/shared/water.png", IGNORE_ALPHA);
171
172   img_waves[0] = new Surface(datadir + "/images/shared/waves-0.png",
173                USE_ALPHA);
174
175   img_waves[1] = new Surface(datadir + "/images/shared/waves-1.png",
176                USE_ALPHA);
177
178   img_waves[2] = new Surface(datadir + "/images/shared/waves-2.png",
179                USE_ALPHA);
180
181
182   /* Pole: */
183
184   img_pole = new Surface(datadir + "/images/shared/pole.png", USE_ALPHA);
185   img_poletop = new Surface(datadir + "/images/shared/poletop.png",
186                USE_ALPHA);
187
188
189   /* Flag: */
190
191   img_flag[0] = new Surface(datadir + "/images/shared/flag-0.png",
192                USE_ALPHA);
193   img_flag[1] = new Surface(datadir + "/images/shared/flag-1.png",
194                USE_ALPHA);
195
196
197   /* Cloud: */
198
199   img_cloud[0][0] = new Surface(datadir + "/images/shared/cloud-00.png",
200                USE_ALPHA);
201
202   img_cloud[0][1] = new Surface(datadir + "/images/shared/cloud-01.png",
203                USE_ALPHA);
204
205   img_cloud[0][2] = new Surface(datadir + "/images/shared/cloud-02.png",
206                USE_ALPHA);
207
208   img_cloud[0][3] = new Surface(datadir + "/images/shared/cloud-03.png",
209                USE_ALPHA);
210
211
212   img_cloud[1][0] = new Surface(datadir + "/images/shared/cloud-10.png",
213                USE_ALPHA);
214
215   img_cloud[1][1] = new Surface(datadir + "/images/shared/cloud-11.png",
216                USE_ALPHA);
217
218   img_cloud[1][2] = new Surface(datadir + "/images/shared/cloud-12.png",
219                USE_ALPHA);
220
221   img_cloud[1][3] = new Surface(datadir + "/images/shared/cloud-13.png",
222                USE_ALPHA);
223
224
225   /* Bad guys: */
226   load_badguy_gfx();
227
228   /* Upgrades: */
229   load_special_gfx();
230
231   /* Weapons: */
232   img_red_glow = new Surface(datadir + "/images/shared/red-glow.png",
233                USE_ALPHA);
234
235   /* Distros: */
236   img_distro[0] = new Surface(datadir + "/images/shared/distro-0.png",
237                USE_ALPHA);
238
239   img_distro[1] = new Surface(datadir + "/images/shared/distro-1.png",
240                USE_ALPHA);
241
242   img_distro[2] = new Surface(datadir + "/images/shared/distro-2.png",
243                USE_ALPHA);
244
245   img_distro[3] = new Surface(datadir + "/images/shared/distro-3.png",
246                USE_ALPHA);
247
248
249   /* Tux life: */
250
251   tux_life = new Surface(datadir + "/images/shared/tux-life.png",
252                          USE_ALPHA);
253
254   /* Sound effects: */
255
256   /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
257                     // initialize sounds[i] with the correct pointer's value:
258                     // NULL or something else. And it will be dangerous to
259                     // play with not-initialized pointers.
260                     // This is also true with if (use_music)
261                     Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
262   */
263   for (i = 0; i < NUM_SOUNDS; i++)
264     sounds[i] = load_sound(datadir + soundfilenames[i]);
265
266   /* Herring song */
267   herring_song = load_song(datadir + "/music/SALCON.MOD");
268 }
269
270
271 /* Free shared data: */
272 void unloadshared(void)
273 {
274   delete sprite_manager;
275
276   int i;
277
278   free_special_gfx();
279
280   for (i = 0; i < 3; i++)
281     {
282       delete tux_right[i];
283       delete tux_left[i];
284     }
285
286   delete bigtux_right_jump;
287   delete bigtux_left_jump;
288
289   for (i = 0; i < 2; i++)
290     {
291       delete cape_right[i];
292       delete cape_left[i];
293       delete bigcape_right[i];
294       delete bigcape_left[i];
295     }
296
297   delete ducktux_left;
298   delete ducktux_right;
299
300   delete skidtux_left;
301   delete skidtux_right;
302
303   free_badguy_gfx();
304
305   delete img_box_full;
306   delete img_box_empty;
307
308   delete img_water;
309   for (i = 0; i < 3; i++)
310     delete img_waves[i];
311
312   delete img_pole;
313   delete img_poletop;
314
315   for (i = 0; i < 2; i++)
316     delete img_flag[i];
317
318   for (i = 0; i < 4; i++)
319     {
320       delete img_distro[i];
321       delete img_cloud[0][i];
322       delete img_cloud[1][i];
323     }
324
325   for (i = 0; i < NUM_SOUNDS; i++)
326     free_chunk(sounds[i]);
327
328   /* free the herring song */
329   free_music( herring_song );
330 }
331
332 /* EOF */