4 // Copyright (C) 2004 Ingo Ruhnke <grumbel@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.
19 #ifndef SUPERTUX_WORLDMAP_H
20 #define SUPERTUX_WORLDMAP_H
25 #include "math/vector.h"
26 #include "audio/musicref.h"
27 #include "video/screen.h"
28 #include "lisp/lisp.h"
29 #include "control/controller.h"
30 #include "statistics.h"
32 #include "tile_manager.h"
33 #include "game_object.h"
40 extern Menu* worldmap_menu;
42 namespace WorldMapNS {
44 enum WorldMapMenuIDs {
58 enum Direction { D_NONE, D_WEST, D_EAST, D_NORTH, D_SOUTH };
60 std::string direction_to_string(Direction d);
61 Direction string_to_direction(const std::string& d);
62 Direction reverse_dir(Direction d);
66 class Tux : public GameObject
69 Direction back_direction;
73 Controller* controller;
75 Direction input_direction;
78 /** Length by which tux is away from its current tile, length is in
79 input_direction direction */
85 Tux(WorldMap* worldmap_);
88 void draw(DrawingContext& context);
89 void update(float elapsed_time);
91 void set_direction(Direction dir);
93 bool is_moving() const { return moving; }
95 Vector get_tile_pos() const { return tile_pos; }
96 void set_tile_pos(Vector p) { tile_pos = p; }
107 Surface* leveldot_green;
108 Surface* leveldot_red;
110 Surface* teleporterdot;
115 typedef std::vector<GameObject*> GameObjects;
116 GameObjects game_objects;
119 TileManager* tile_manager;
126 /** Optional flags: */
128 /** Position to swap to player */
129 Vector teleport_dest;
131 /** Message to show in the Map */
132 std::string map_message;
133 bool passive_message;
135 /** Hide special tile */
138 /** Only applies actions (ie. passive messages) when going to that direction */
139 bool apply_action_north;
140 bool apply_action_east;
141 bool apply_action_south;
142 bool apply_action_west;
153 /** Statistics for level tiles */
154 Statistics statistics;
156 /** Optional flags: */
158 /** Check if this level should be vertically flipped */
161 /** Script that is run when the level is successfully finished */
162 std::string extro_script;
164 /** Go to this world */
165 std::string next_worldmap;
167 /** Quit the worldmap */
170 /** If false, disables the auto walking after finishing a level */
173 // Directions which are walkable from this level
180 /** Variables to deal with the passive map messages */
181 Timer passive_message_timer;
182 std::string passive_message;
185 std::string map_filename;
186 std::string levels_path;
188 typedef std::vector<SpecialTile> SpecialTiles;
189 SpecialTiles special_tiles;
190 typedef std::vector<Level> Levels;
192 typedef std::vector<SpawnPoint*> SpawnPoints;
193 SpawnPoints spawn_points;
198 std::string savegame_file;
200 std::string intro_script;
201 bool intro_displayed;
203 void get_level_title(Level& level);
205 void draw_status(DrawingContext& context);
207 // to avoid calculating total stats all the time. This way only
208 // when need, it is calculated.
209 Statistics total_stats;
210 void calculate_total_stats();
223 void add_object(GameObject* object);
224 void clear_objects();
226 /** Update Tux position */
227 void update(float delta);
229 /** Draw one frame */
230 void draw(DrawingContext& context);
232 Vector get_next_tile(Vector pos, Direction direction);
233 const Tile* at(Vector pos);
235 WorldMap::Level* at_level();
236 WorldMap::SpecialTile* at_special_tile();
238 /** Check if it is possible to walk from \a pos into \a direction,
239 if possible, write the new position to \a new_pos */
240 bool path_ok(Direction direction, Vector pos, Vector* new_pos);
242 /* Save map to slot */
243 void savegame(const std::string& filename);
244 /* Load map from slot
245 You should call set_map_filename() before this */
246 void loadgame(const std::string& filename);
247 /* Load map directly from file */
248 void loadmap(const std::string& filename);
250 const std::string& get_world_title() const
253 void set_map_filename(std::string filename)
254 { map_filename = filename; }
257 void on_escape_press();
258 void parse_special_tile(const lisp::Lisp* lisp);
259 void parse_level_tile(const lisp::Lisp* lisp);
262 } // namespace WorldMapNS
266 /* Local Variables: */