Updated code to support new stuff from 0.1.2.
[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                                        "/sounds/warp.wav"
79                                     };
80
81
82 Font* gold_text;
83 Font* blue_text;
84 Font* gray_text;
85 Font* yellow_nums;
86 Font* white_text;
87 Font* white_small_text;
88 Font* white_big_text;                               
89                                     
90 /* Load graphics/sounds shared between all levels: */
91 void loadshared()
92 {
93
94   /* Load global images: */
95   gold_text = new Font(datadir + "/images/fonts/gold.png", Font::TEXT, 16,18);
96   blue_text = new Font(datadir + "/images/fonts/blue.png", Font::TEXT, 16,18,3);
97   white_text  = new Font(datadir + "/images/fonts/white.png",
98                          Font::TEXT, 16,18);
99   gray_text  = new Font(datadir + "/images/fonts/gray.png",
100                         Font::TEXT, 16,18);
101   white_small_text = new Font(datadir + "/images/fonts/white-small.png",
102                               Font::TEXT, 8,9, 1);
103   white_big_text   = new Font(datadir + "/images/fonts/white-big.png",
104                               Font::TEXT, 20,22, 3);
105   yellow_nums = new Font(datadir + "/images/fonts/numbers.png",
106                          Font::NUM, 32,32);
107
108   Menu::default_font = white_text;
109   Menu::active_font = blue_text;
110   Menu::deactive_font = gray_text;
111   Menu::label_font = white_big_text;
112   Menu::field_font = gold_text;
113   
114   Button::info_font = white_small_text;
115
116   int i;
117
118   sprite_manager = new SpriteManager(datadir + "/images/supertux.strf");
119
120   /* Tuxes: */
121   smalltux_star = sprite_manager->load("smalltux-star");
122   bigtux_star = sprite_manager->load("bigtux-star");
123   smalltux_gameover = sprite_manager->load("smalltux-gameover");
124
125   char img_name[1024];
126   for (int i = 0; i < GROWING_FRAMES; i++)
127     {
128       sprintf(img_name, "%s/images/shared/tux-grow-left-%i.png", datadir.c_str(), i+1);
129       growingtux_left[i] = new Surface(img_name, true);
130
131       sprintf(img_name, "%s/images/shared/tux-grow-right-%i.png", datadir.c_str(), i+1);
132       growingtux_right[i] = new Surface(img_name, true);
133     }
134
135   small_tux = new TuxBodyParts();
136   small_tux->head = sprite_manager->load("big-tux-head");
137   small_tux->body = sprite_manager->load("big-tux-body");
138   small_tux->arms = sprite_manager->load("big-tux-arms");
139   small_tux->feet = sprite_manager->load("big-tux-feet");
140
141   big_tux = new TuxBodyParts();
142   big_tux->head = sprite_manager->load("big-tux-head");
143   big_tux->body = sprite_manager->load("big-tux-body");
144   big_tux->arms = sprite_manager->load("big-tux-arms");
145   big_tux->feet = sprite_manager->load("big-tux-feet");
146
147   fire_tux = new TuxBodyParts();
148   fire_tux->head = sprite_manager->load("big-fire-tux-head");
149   fire_tux->body = sprite_manager->load("big-tux-body");
150   fire_tux->arms = sprite_manager->load("big-tux-arms");
151   fire_tux->feet = sprite_manager->load("big-tux-feet");
152
153   ice_tux = new TuxBodyParts();
154   ice_tux->head = sprite_manager->load("big-tux-head");
155   ice_tux->body = sprite_manager->load("big-tux-body");
156   ice_tux->arms = sprite_manager->load("big-tux-arms");
157   ice_tux->feet = sprite_manager->load("big-tux-feet");
158
159   /* Water: */
160   img_water = new Surface(datadir + "/images/shared/water.png", false);
161
162   img_waves[0] = new Surface(datadir + "/images/shared/waves-0.png",
163                              true);
164
165   img_waves[1] = new Surface(datadir + "/images/shared/waves-1.png",
166                              true);
167
168
169   img_waves[2] = new Surface(datadir + "/images/shared/waves-2.png",
170                              true);
171
172
173   /* Pole: */
174
175   img_pole = new Surface(datadir + "/images/shared/pole.png", true);
176   img_poletop = new Surface(datadir + "/images/shared/poletop.png",
177                             true);
178
179
180   /* Flag: */
181
182   img_flag[0] = new Surface(datadir + "/images/shared/flag-0.png",
183                             true);
184   img_flag[1] = new Surface(datadir + "/images/shared/flag-1.png",
185                             true);
186
187
188   /* Cloud: */
189
190   img_cloud[0][0] = new Surface(datadir + "/images/shared/cloud-00.png",
191                                 true);
192
193   img_cloud[0][1] = new Surface(datadir + "/images/shared/cloud-01.png",
194                                 true);
195
196   img_cloud[0][2] = new Surface(datadir + "/images/shared/cloud-02.png",
197                                 true);
198
199   img_cloud[0][3] = new Surface(datadir + "/images/shared/cloud-03.png",
200                                 true);
201
202
203   img_cloud[1][0] = new Surface(datadir + "/images/shared/cloud-10.png",
204                                 true);
205
206   img_cloud[1][1] = new Surface(datadir + "/images/shared/cloud-11.png",
207                                 true);
208
209   img_cloud[1][2] = new Surface(datadir + "/images/shared/cloud-12.png",
210                                 true);
211
212   img_cloud[1][3] = new Surface(datadir + "/images/shared/cloud-13.png",
213                                 true);
214
215
216   /* Bad guys: */
217   load_badguy_gfx();
218
219   /* Upgrades: */
220   load_special_gfx();
221
222   /* Objects */
223   load_object_gfx();
224
225   // load the door object graphics:
226   door = sprite_manager->load("door");
227   for (int i = 0; i < DOOR_OPENING_FRAMES; i++)
228     {
229       sprintf(img_name, "%s/images/shared/door-%i.png", datadir.c_str(), i+1);
230       door_opening[i] = new Surface(img_name, true);
231     }
232
233   /* Distros: */
234   img_distro[0] = new Surface(datadir + "/images/tilesets/coin1.png",
235                               true);
236
237   img_distro[1] = new Surface(datadir + "/images/tilesets/coin2.png",
238                               true);
239
240   img_distro[2] = new Surface(datadir + "/images/tilesets/coin3.png",
241                               true);
242
243   img_distro[3] = new Surface(datadir + "/images/tilesets/coin2.png",
244                               true);
245
246
247   /* Tux life: */
248
249   tux_life = new Surface(datadir + "/images/shared/tux-life.png",
250                          true);
251
252   /* Sound effects: */
253
254   /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound"
255                     // initialize sounds[i] with the correct pointer's value:
256                     // NULL or something else. And it will be dangerous to
257                     // play with not-initialized pointers.
258                     // This is also true with if (use_music)
259                     Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :)
260   */
261   for (i = 0; i < NUM_SOUNDS; i++)
262     SoundManager::get
263       ()->add_sound(SoundManager::get
264                       ()->load_sound(datadir + soundfilenames[i]),i);
265
266   /* Herring song */
267   herring_song = SoundManager::get
268                    ()->load_music(datadir + "/music/SALCON.MOD");
269   level_end_song = SoundManager::get
270                      ()->load_music(datadir + "/music/leveldone.mod");
271 }
272
273 /* Free shared data: */
274 void unloadshared(void)
275 {
276   /* Free global images: */
277   delete gold_text;
278   delete white_text;
279   delete blue_text;
280   delete gray_text;
281   delete white_small_text;
282   delete white_big_text;
283   delete yellow_nums;
284   
285   int i;
286
287   free_special_gfx();
288   free_badguy_gfx();
289
290   delete img_water;
291   for (i = 0; i < 3; i++)
292     delete img_waves[i];
293
294   delete img_pole;
295   delete img_poletop;
296
297   for (i = 0; i < 2; i++)
298     delete img_flag[i];
299
300   for (i = 0; i < 4; i++)
301     {
302       delete img_distro[i];
303       delete img_cloud[0][i];
304       delete img_cloud[1][i];
305     }
306
307   delete tux_life;
308
309   delete small_tux;
310   delete big_tux;
311   delete fire_tux;
312   delete ice_tux;
313
314   for (int i = 0; i < GROWING_FRAMES; i++)
315   {
316     delete growingtux_left[i];
317     delete growingtux_right[i];
318   }
319
320   // door game object:
321
322   for (int i = 0; i < DOOR_OPENING_FRAMES; i++)
323     delete door_opening[i];
324
325   delete sprite_manager;
326   sprite_manager = 0;
327   sound_manager = 0;
328 }
329
330 /* EOF */