Check if this fixes the jamming.
[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 "app/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 "special/sprite_manager.h"
28 #include "audio/sound_manager.h"
29 #include "app/setup.h"
30 #include "door.h"
31 #include "gui/button.h"
32
33 Surface* img_waves[3]; 
34 Surface* img_water;
35 Surface* img_pole;
36 Surface* img_poletop;
37 Surface* img_flag[2];
38 Surface* img_cloud[2][4];
39 Surface* img_distro[4];
40
41 Menu* main_menu      = 0;
42 Menu* game_menu      = 0;
43 Menu* options_menu   = 0;
44 Menu* options_keys_menu     = 0;
45 Menu* options_joystick_menu = 0;
46 Menu* highscore_menu = 0;
47 Menu* load_game_menu = 0;
48 Menu* save_game_menu = 0;
49 Menu* contrib_menu   = 0;
50 Menu* contrib_subset_menu   = 0;
51
52 MusicRef herring_song;
53 MusicRef level_end_song;
54
55 SpriteManager* sprite_manager = 0;
56 SoundManager* sound_manager = 0;
57
58 char * soundfilenames[NUM_SOUNDS] = {
59                                        "/sounds/jump.wav",
60                                        "/sounds/bigjump.wav",
61                                        "/sounds/skid.wav",
62                                        "/sounds/coin.wav",
63                                        "/sounds/invincible.wav",
64                                        "/sounds/brick.wav",
65                                        "/sounds/hurt.wav",
66                                        "/sounds/squish.wav",
67                                        "/sounds/fall.wav",
68                                        "/sounds/ricochet.wav",
69                                        "/sounds/bump-upgrade.wav",
70                                        "/sounds/upgrade.wav",
71                                        "/sounds/grow.wav",
72                                        "/sounds/fire-flower.wav",
73                                        "/sounds/shoot.wav",
74                                        "/sounds/lifeup.wav",
75                                        "/sounds/stomp.wav",
76                                        "/sounds/kick.wav",
77                                        "/sounds/explosion.wav"
78                                     };
79
80
81 Font* gold_text;
82 Font* blue_text;
83 Font* gray_text;
84 Font* yellow_nums;
85 Font* white_text;
86 Font* white_small_text;
87 Font* white_big_text;                               
88                                     
89 /* Load graphics/sounds shared between all levels: */
90 void loadshared()
91 {
92
93   /* Load global images: */
94   gold_text = new Font(datadir + "/images/fonts/gold.png", Font::TEXT, 16,18);
95   blue_text = new Font(datadir + "/images/fonts/blue.png", Font::TEXT, 16,18,3);
96   white_text  = new Font(datadir + "/images/fonts/white.png",
97                          Font::TEXT, 16,18);
98   gray_text  = new Font(datadir + "/images/fonts/gray.png",
99                         Font::TEXT, 16,18);
100   white_small_text = new Font(datadir + "/images/fonts/white-small.png",
101                               Font::TEXT, 8,9, 1);
102   white_big_text   = new Font(datadir + "/images/fonts/white-big.png",
103                               Font::TEXT, 20,22, 3);
104   yellow_nums = new Font(datadir + "/images/fonts/numbers.png",
105                          Font::NUM, 32,32);
106
107   Menu::default_font = white_text;
108   Menu::active_font = blue_text;
109   Menu::deactive_font = gray_text;
110   Menu::label_font = white_big_text;
111   Menu::field_font = gold_text;
112   
113   Button::info_font = white_small_text;
114
115   int i;
116
117   sprite_manager = new SpriteManager(datadir + "/supertux.strf");
118
119   /* Tuxes: */
120   smalltux_star = sprite_manager->load("smalltux-star");
121   largetux_star = sprite_manager->load("largetux-star");
122   smalltux_gameover = sprite_manager->load("smalltux-gameover");
123
124   char img_name[1024];
125   for (int i = 0; i < GROWING_FRAMES; i++)
126     {
127       sprintf(img_name, "%s/images/shared/tux-grow-left-%i.png", datadir.c_str(), i+1);
128       growingtux_left[i] = new Surface(img_name, true);
129
130       sprintf(img_name, "%s/images/shared/tux-grow-right-%i.png", datadir.c_str(), i+1);
131       growingtux_right[i] = new Surface(img_name, true);
132     }
133
134   small_tux = sprite_manager->load("small-tux");
135   big_tux   = sprite_manager->load("big-tux");
136   ice_tux   = sprite_manager->load("ice-tux");
137   fire_tux  = sprite_manager->load("fire-tux");
138
139   tux_arm = sprite_manager->load("tux-arm");
140
141   /* Water: */
142   img_water = new Surface(datadir + "/images/shared/water.png", false);
143
144   img_waves[0] = new Surface(datadir + "/images/shared/waves-0.png",
145                              true);
146
147   img_waves[1] = new Surface(datadir + "/images/shared/waves-1.png",
148                              true);
149
150
151   img_waves[2] = new Surface(datadir + "/images/shared/waves-2.png",
152                              true);
153
154
155   /* Pole: */
156
157   img_pole = new Surface(datadir + "/images/shared/pole.png", true);
158   img_poletop = new Surface(datadir + "/images/shared/poletop.png",
159                             true);
160
161
162   /* Flag: */
163
164   img_flag[0] = new Surface(datadir + "/images/shared/flag-0.png",
165                             true);
166   img_flag[1] = new Surface(datadir + "/images/shared/flag-1.png",
167                             true);
168
169
170   /* Cloud: */
171
172   img_cloud[0][0] = new Surface(datadir + "/images/shared/cloud-00.png",
173                                 true);
174
175   img_cloud[0][1] = new Surface(datadir + "/images/shared/cloud-01.png",
176                                 true);
177
178   img_cloud[0][2] = new Surface(datadir + "/images/shared/cloud-02.png",
179                                 true);
180
181   img_cloud[0][3] = new Surface(datadir + "/images/shared/cloud-03.png",
182                                 true);
183
184
185   img_cloud[1][0] = new Surface(datadir + "/images/shared/cloud-10.png",
186                                 true);
187
188   img_cloud[1][1] = new Surface(datadir + "/images/shared/cloud-11.png",
189                                 true);
190
191   img_cloud[1][2] = new Surface(datadir + "/images/shared/cloud-12.png",
192                                 true);
193
194   img_cloud[1][3] = new Surface(datadir + "/images/shared/cloud-13.png",
195                                 true);
196
197
198   /* Bad guys: */
199   load_badguy_gfx();
200
201   /* Upgrades: */
202   load_special_gfx();
203
204   /* Objects */
205   load_object_gfx();
206
207   // load the door object graphics:
208   door = sprite_manager->load("door");
209   for (int i = 0; i < DOOR_OPENING_FRAMES; i++)
210     {
211       sprintf(img_name, "%s/images/shared/door-%i.png", datadir.c_str(), i+1);
212       door_opening[i] = new Surface(img_name, true);
213     }
214
215   /* Distros: */
216   img_distro[0] = new Surface(datadir + "/images/tilesets/coin1.png",
217                               true);
218
219   img_distro[1] = new Surface(datadir + "/images/tilesets/coin2.png",
220                               true);
221
222   img_distro[2] = new Surface(datadir + "/images/tilesets/coin3.png",
223                               true);
224
225   img_distro[3] = new Surface(datadir + "/images/tilesets/coin2.png",
226                               true);
227
228
229   /* Tux life: */
230
231   tux_life = new Surface(datadir + "/images/shared/tux-life.png",
232                          true);
233
234   /* Sound effects: */
235
236   /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
237                     // initialize sounds[i] with the correct pointer's value:
238                     // NULL or something else. And it will be dangerous to
239                     // play with not-initialized pointers.
240                     // This is also true with if (use_music)
241                     Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
242   */
243   for (i = 0; i < NUM_SOUNDS; i++)
244     SoundManager::get
245       ()->add_sound(SoundManager::get
246                       ()->load_sound(datadir + soundfilenames[i]),i);
247
248   /* Herring song */
249   herring_song = SoundManager::get
250                    ()->load_music(datadir + "/music/SALCON.MOD");
251   level_end_song = SoundManager::get
252                      ()->load_music(datadir + "/music/leveldone.mod");
253 }
254
255 /* Free shared data: */
256 void unloadshared(void)
257 {
258   /* Free global images: */
259   delete gold_text;
260   delete white_text;
261   delete blue_text;
262   delete gray_text;
263   delete white_small_text;
264   delete white_big_text;
265   delete yellow_nums;
266   
267   int i;
268
269   free_special_gfx();
270   free_badguy_gfx();
271
272   delete img_water;
273   for (i = 0; i < 3; i++)
274     delete img_waves[i];
275
276   delete img_pole;
277   delete img_poletop;
278
279   for (i = 0; i < 2; i++)
280     delete img_flag[i];
281
282   for (i = 0; i < 4; i++)
283     {
284       delete img_distro[i];
285       delete img_cloud[0][i];
286       delete img_cloud[1][i];
287     }
288
289   delete tux_life;
290
291   for (int i = 0; i < GROWING_FRAMES; i++)
292   {
293     delete growingtux_left[i];
294     delete growingtux_right[i];
295   }
296
297   // door game object:
298
299   for (int i = 0; i < DOOR_OPENING_FRAMES; i++)
300     delete door_opening[i];
301
302   delete sprite_manager;
303   sprite_manager = 0;
304   sound_manager = 0;
305 }
306
307 /* EOF */