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.hpp"
26 #include "video/screen.hpp"
27 #include "lisp/lisp.hpp"
28 #include "control/controller.hpp"
29 #include "statistics.hpp"
31 #include "tile_manager.hpp"
32 #include "game_object.hpp"
39 extern Menu* worldmap_menu;
41 namespace WorldMapNS {
43 enum WorldMapMenuIDs {
57 enum Direction { D_NONE, D_WEST, D_EAST, D_NORTH, D_SOUTH };
59 std::string direction_to_string(Direction d);
60 Direction string_to_direction(const std::string& d);
61 Direction reverse_dir(Direction d);
65 class Tux : public GameObject
68 Direction back_direction;
72 Controller* controller;
74 Direction input_direction;
77 /** Length by which tux is away from its current tile, length is in
78 input_direction direction */
84 Tux(WorldMap* worldmap_);
87 void draw(DrawingContext& context);
88 void update(float elapsed_time);
90 void set_direction(Direction dir);
92 bool is_moving() const { return moving; }
94 Vector get_tile_pos() const { return tile_pos; }
95 void set_tile_pos(Vector p) { tile_pos = p; }
106 Surface* leveldot_green;
107 Surface* leveldot_red;
109 Surface* teleporterdot;
114 typedef std::vector<GameObject*> GameObjects;
115 GameObjects game_objects;
118 TileManager* tile_manager;
125 /** Optional flags: */
127 /** Position to swap to player */
128 Vector teleport_dest;
130 /** Message to show in the Map */
131 std::string map_message;
132 bool passive_message;
134 /** Hide special tile */
137 /** Only applies actions (ie. passive messages) when going to that direction */
138 bool apply_action_north;
139 bool apply_action_east;
140 bool apply_action_south;
141 bool apply_action_west;
152 /** Statistics for level tiles */
153 Statistics statistics;
155 /** Optional flags: */
157 /** Check if this level should be vertically flipped */
160 /** Script that is run when the level is successfully finished */
161 std::string extro_script;
163 /** Go to this world */
164 std::string next_worldmap;
166 /** Quit the worldmap */
169 /** If false, disables the auto walking after finishing a level */
172 // Directions which are walkable from this level
179 /** Variables to deal with the passive map messages */
180 Timer passive_message_timer;
181 std::string passive_message;
184 std::string map_filename;
185 std::string levels_path;
187 typedef std::vector<SpecialTile> SpecialTiles;
188 SpecialTiles special_tiles;
189 typedef std::vector<Level> Levels;
191 typedef std::vector<SpawnPoint*> SpawnPoints;
192 SpawnPoints spawn_points;
195 std::string savegame_file;
197 std::string intro_script;
198 bool intro_displayed;
200 void get_level_title(Level& level);
202 void draw_status(DrawingContext& context);
204 // to avoid calculating total stats all the time. This way only
205 // when need, it is calculated.
206 Statistics total_stats;
207 void calculate_total_stats();
220 void add_object(GameObject* object);
221 void clear_objects();
223 /** Update Tux position */
224 void update(float delta);
226 /** Draw one frame */
227 void draw(DrawingContext& context);
229 Vector get_next_tile(Vector pos, Direction direction);
230 const Tile* at(Vector pos);
232 WorldMap::Level* at_level();
233 WorldMap::SpecialTile* at_special_tile();
235 /** Check if it is possible to walk from \a pos into \a direction,
236 if possible, write the new position to \a new_pos */
237 bool path_ok(Direction direction, Vector pos, Vector* new_pos);
239 /* Save map to slot */
240 void savegame(const std::string& filename);
241 /* Load map from slot
242 You should call set_map_filename() before this */
243 void loadgame(const std::string& filename);
244 /* Load map directly from file */
245 void loadmap(const std::string& filename);
247 const std::string& get_world_title() const
250 void set_map_filename(std::string filename)
251 { map_filename = filename; }
254 void on_escape_press();
255 void parse_special_tile(const lisp::Lisp* lisp);
256 void parse_level_tile(const lisp::Lisp* lisp);
259 } // namespace WorldMapNS
263 /* Local Variables: */