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