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