ef251a65820556949c11a81eecb56f2ab3fbc519
[supertux.git] / src / resources.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2003 Tobias Glaesser <tobi.web@gmx.de>
5 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 //
7 //  This program is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU General Public License
9 //  as published by the Free Software Foundation; either version 2
10 //  of the License, or (at your option) any later version.
11 //
12 //  This program is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 //  GNU General Public License for more details.
16 //
17 //  You should have received a copy of the GNU General Public License
18 //  along with this program; if not, write to the Free Software
19 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 #include <config.h>
21
22 #include "sprite/sprite_manager.hpp"
23 #include "gui/menu.hpp"
24 #include "gui/button.hpp"
25 #include "resources.hpp"
26 #include "file_system.hpp"
27 #include "tile_manager.hpp"
28 #include "object/gameobjs.hpp"
29 #include "object/player.hpp"
30
31 MouseCursor* mouse_cursor = NULL;
32
33 Font* gold_text = NULL;
34 Font* blue_text = NULL;
35 Font* gray_text = NULL;
36 Font* white_text = NULL;
37 Font* white_small_text = NULL;
38 Font* white_big_text = NULL;
39
40 /* Load graphics/sounds shared between all levels: */
41 void load_shared()
42 {
43   /* Load the mouse-cursor */
44   mouse_cursor = new MouseCursor("images/engine/menu/mousecursor.png");
45   MouseCursor::set_current(mouse_cursor);
46
47   /* Load global images: */
48   gold_text  = new Font(Font::FIXED,
49                         "images/engine/fonts/gold.png",
50                         "images/engine/fonts/shadow.png", 16, 18);
51   blue_text  = new Font(Font::FIXED,
52                         "images/engine/fonts/blue.png",
53                         "images/engine/fonts/shadow.png", 16, 18, 3);
54   //  white_text = new Font("images/engine/fonts/white.png",
55   // "images/engine/fonts/shadow.png", 16, 18);
56   white_text = new Font(Font::VARIABLE,
57                         "images/engine/fonts/white.png", 16, 18);
58   gray_text  = new Font(Font::FIXED,
59                         "images/engine/fonts/gray.png",
60                        "images/engine/fonts/shadow.png", 16, 18);
61   white_small_text = new Font(Font::VARIABLE,
62                               "images/engine/fonts/white-small.png",
63                               8, 9);
64   //                              "images/engine/fonts/shadow-small.png", 8, 9, 1);
65   white_big_text = new Font(Font::FIXED,
66                             "images/engine/fonts/white-big.png",
67                             "images/engine/fonts/shadow-big.png", 20, 22, 3);
68
69   Menu::default_font  = white_text;
70   Menu::active_font   = blue_text;
71   Menu::deactive_font = gray_text;
72   Menu::label_font    = white_big_text;
73   Menu::field_font    = gold_text;
74
75   Button::info_font = white_small_text;
76
77   sprite_manager = new SpriteManager();
78   tile_manager   = new TileManager("images/tiles.strf");
79
80   /* Tuxes: */
81   char img_name[1024];
82   for (int i = 0; i < GROWING_FRAMES; i++)
83     {
84       snprintf(img_name, sizeof(img_name), "images/creatures/tux_grow/left-%i.png", i+1);
85       growingtux_left[i] = new Surface(img_name);
86
87       snprintf(img_name, sizeof(img_name), "images/creatures/tux_grow/right-%i.png", i+1);
88       growingtux_right[i] = new Surface(img_name);
89     }
90
91   small_tux = new TuxBodyParts();
92   small_tux->head = 0;
93   small_tux->body = sprite_manager->create("images/creatures/tux_small/small-tux-body.sprite");
94   small_tux->arms = sprite_manager->create("images/creatures/tux_small/small-tux-arms.sprite");
95   small_tux->feet = 0;
96
97   big_tux = new TuxBodyParts();
98   big_tux->head = sprite_manager->create("images/creatures/tux_big/big-tux-head.sprite");
99   big_tux->body = sprite_manager->create("images/creatures/tux_big/big-tux-body.sprite");
100   big_tux->arms = sprite_manager->create("images/creatures/tux_big/big-tux-arms.sprite");
101   big_tux->feet = sprite_manager->create("images/creatures/tux_big/big-tux-feet.sprite");
102
103   fire_tux = new TuxBodyParts();
104   fire_tux->head = sprite_manager->create("images/creatures/tux_big/big-fire-tux-head.sprite");
105   fire_tux->body = sprite_manager->create("images/creatures/tux_big/big-tux-body.sprite");
106   fire_tux->arms = sprite_manager->create("images/creatures/tux_big/big-tux-arms.sprite");
107   fire_tux->feet = sprite_manager->create("images/creatures/tux_big/big-tux-feet.sprite");
108
109   ice_tux = new TuxBodyParts();
110   ice_tux->head = sprite_manager->create("images/creatures/tux_big/big-ice-tux-head.sprite");
111   ice_tux->body = sprite_manager->create("images/creatures/tux_big/big-tux-body.sprite");
112   ice_tux->arms = sprite_manager->create("images/creatures/tux_big/big-tux-arms.sprite");
113   ice_tux->feet = sprite_manager->create("images/creatures/tux_big/big-tux-feet.sprite");
114
115   player_status = new PlayerStatus();
116 }
117
118 /* Free shared data: */
119 void unload_shared()
120 {
121   /* Free global images: */
122   delete gold_text;
123   delete white_text;
124   delete blue_text;
125   delete gray_text;
126   delete white_small_text;
127   delete white_big_text;
128
129   delete small_tux;
130   delete big_tux;
131   delete fire_tux;
132   delete ice_tux;
133
134   for (int i = 0; i < GROWING_FRAMES; i++) {
135     delete growingtux_left[i];
136     delete growingtux_right[i];
137   }
138
139   delete sprite_manager;
140   sprite_manager = NULL;
141   delete tile_manager;
142   tile_manager = NULL;
143
144   /* Free mouse-cursor */
145   delete mouse_cursor;
146 }