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