3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
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.
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.
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.
22 #include "app/globals.h"
23 #include "sprite/sprite_manager.h"
24 #include "app/setup.h"
26 #include "gui/button.h"
27 #include "resources.h"
28 #include "tile_manager.h"
29 #include "object/gameobjs.h"
30 #include "object/player.h"
32 MusicRef herring_song;
33 MusicRef level_end_song;
34 MusicRef credits_song;
36 SpriteManager* sprite_manager = 0;
37 TileManager* tile_manager = 0;
38 SoundManager* sound_manager = 0;
45 Font* white_small_text;
48 /* Load graphics/sounds shared between all levels: */
51 /* Load GUI/menu images: */
52 checkbox = new Surface(datadir + "/images/status/checkbox.png", true);
53 checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", true);
54 back = new Surface(datadir + "/images/status/back.png", true);
55 arrow_left = new Surface(datadir + "/images/icons/left.png", true);
56 arrow_right = new Surface(datadir + "/images/icons/right.png", true);
58 /* Load the mouse-cursor */
59 mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1);
60 MouseCursor::set_current(mouse_cursor);
62 /* Load global images: */
63 gold_text = new Font(datadir + "/images/fonts/gold.png", Font::TEXT, 16,18);
64 blue_text = new Font(datadir + "/images/fonts/blue.png", Font::TEXT, 16,18,3);
65 white_text = new Font(datadir + "/images/fonts/white.png",
67 gray_text = new Font(datadir + "/images/fonts/gray.png",
69 white_small_text = new Font(datadir + "/images/fonts/white-small.png",
71 white_big_text = new Font(datadir + "/images/fonts/white-big.png",
72 Font::TEXT, 20,22, 3);
73 yellow_nums = new Font(datadir + "/images/fonts/numbers.png",
76 Menu::default_font = white_text;
77 Menu::active_font = blue_text;
78 Menu::deactive_font = gray_text;
79 Menu::label_font = white_big_text;
80 Menu::field_font = gold_text;
82 Button::info_font = white_small_text;
86 sprite_manager = new SpriteManager(
87 get_resource_filename("/images/supertux.strf"));
88 tile_manager = new TileManager("/images/tilesets/supertux.stgt");
92 for (int i = 0; i < GROWING_FRAMES; i++)
94 sprintf(img_name, "%s/images/shared/tux-grow-left-%i.png", datadir.c_str(), i+1);
95 growingtux_left[i] = new Surface(img_name, true);
97 sprintf(img_name, "%s/images/shared/tux-grow-right-%i.png", datadir.c_str(), i+1);
98 growingtux_right[i] = new Surface(img_name, true);
101 small_tux = new TuxBodyParts();
103 small_tux->body = sprite_manager->create("small-tux-body");
104 small_tux->arms = sprite_manager->create("small-tux-arms");
107 big_tux = new TuxBodyParts();
108 big_tux->head = sprite_manager->create("big-tux-head");
109 big_tux->body = sprite_manager->create("big-tux-body");
110 big_tux->arms = sprite_manager->create("big-tux-arms");
111 big_tux->feet = sprite_manager->create("big-tux-feet");
113 fire_tux = new TuxBodyParts();
114 fire_tux->head = sprite_manager->create("big-fire-tux-head");
115 fire_tux->body = sprite_manager->create("big-tux-body");
116 fire_tux->arms = sprite_manager->create("big-tux-arms");
117 fire_tux->feet = sprite_manager->create("big-tux-feet");
119 ice_tux = new TuxBodyParts();
120 ice_tux->head = sprite_manager->create("big-tux-head");
121 ice_tux->body = sprite_manager->create("big-tux-body");
122 ice_tux->arms = sprite_manager->create("big-tux-arms");
123 ice_tux->feet = sprite_manager->create("big-tux-feet");
129 tux_life = new Surface(datadir + "/images/shared/tux-life.png",
133 sound_manager->preload_sound("jump");
134 sound_manager->preload_sound("bigjump");
135 sound_manager->preload_sound("skid");
136 sound_manager->preload_sound("coin");
137 sound_manager->preload_sound("invincible");
138 sound_manager->preload_sound("brick");
139 sound_manager->preload_sound("hurt");
140 sound_manager->preload_sound("squish");
141 sound_manager->preload_sound("fall");
142 sound_manager->preload_sound("ricochet");
143 sound_manager->preload_sound("bump-upgrade");
144 sound_manager->preload_sound("upgrade");
145 sound_manager->preload_sound("grow");
146 sound_manager->preload_sound("fire-flower");
147 sound_manager->preload_sound("shoot");
148 sound_manager->preload_sound("lifeup");
149 sound_manager->preload_sound("stomp");
150 sound_manager->preload_sound("kick");
151 sound_manager->preload_sound("explosion");
152 sound_manager->preload_sound("warp");
153 sound_manager->preload_sound("fireworks");
156 herring_song = sound_manager->load_music(datadir + "/music/salcon.mod");
157 level_end_song = sound_manager->load_music(datadir + "/music/leveldone.mod");
160 /* Free shared data: */
163 /* Free global images: */
168 delete white_small_text;
169 delete white_big_text;
181 for (int i = 0; i < GROWING_FRAMES; i++) {
182 delete growingtux_left[i];
183 delete growingtux_right[i];
186 delete sprite_manager;
191 /* Free GUI/menu images: */
193 delete checkbox_checked;
198 /* Free mouse-cursor */
202 std::string get_resource_filename(const std::string& resource)
204 std::string filepath = user_dir + resource;
205 if(FileSystem::faccessible(filepath))
208 filepath = datadir + resource;
209 if(FileSystem::faccessible(filepath))
212 std::cerr << "Couldn't find resource: '" << resource << "'." << std::endl;