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