4 // Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
5 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
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.
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.
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 #ifndef SUPERTUX_WORLDMAP_H
21 #define SUPERTUX_WORLDMAP_H
26 #include "math/vector.hpp"
27 #include "video/screen.hpp"
28 #include "lisp/lisp.hpp"
29 #include "control/controller.hpp"
30 #include "statistics.hpp"
33 #include "tile_manager.hpp"
34 #include "game_object.hpp"
35 #include "console.hpp"
42 extern Menu* worldmap_menu;
44 namespace WorldMapNS {
46 enum WorldMapMenuIDs {
60 enum Direction { D_NONE, D_WEST, D_EAST, D_NORTH, D_SOUTH };
62 std::string direction_to_string(Direction d);
63 Direction string_to_direction(const std::string& d);
64 Direction reverse_dir(Direction d);
68 class Tux : public GameObject
71 Direction back_direction;
75 Controller* controller;
77 Direction input_direction;
80 /** Length by which tux is away from its current tile, length is in
81 input_direction direction */
87 bool canWalk(const Tile* tile, Direction dir); /**< check if we can leave "tile" in direction "dir" */
88 void updateInputDirection(); /**< if controller was pressed, update input_direction */
89 void tryStartWalking(); /**< try starting to walk in input_direction */
90 void tryContinueWalking(float elapsed_time); /**< try to continue walking in current direction */
93 Tux(WorldMap* worldmap_);
96 void draw(DrawingContext& context);
97 void update(float elapsed_time);
99 void set_direction(Direction dir);
101 bool is_moving() const { return moving; }
103 Vector get_tile_pos() const { return tile_pos; }
104 void set_tile_pos(Vector p) { tile_pos = p; }
108 class WorldMap : public Screen
113 Surface* leveldot_green;
114 Surface* leveldot_red;
116 Sprite* teleporterdot;
117 static WorldMap* current_;
119 Vector camera_offset;
124 typedef std::vector<GameObject*> GameObjects;
125 GameObjects game_objects;
128 TileManager* tile_manager;
137 /** Optional flags: */
139 /** Sprite to render instead of guessing what image to draw */
142 /** Position to swap to player */
143 Vector teleport_dest;
145 /** Message to show in the Map */
146 std::string map_message;
147 bool passive_message;
149 /** Hide special tile */
152 /** Only applies actions (ie. passive messages) when going to that direction */
153 bool apply_action_north;
154 bool apply_action_east;
155 bool apply_action_south;
156 bool apply_action_west;
169 /** Statistics for level tiles */
170 Statistics statistics;
172 /** Optional flags: */
174 /** Check if this level should be vertically flipped */
177 /** Script that is run when the level is successfully finished */
178 std::string extro_script;
180 /** Go to this world */
181 std::string next_worldmap;
183 /** Quit the worldmap */
186 /** If false, disables the auto walking after finishing a level */
189 // Directions which are walkable from this level
196 /** Variables to deal with the passive map messages */
197 Timer passive_message_timer;
198 std::string passive_message;
201 std::string map_filename;
202 std::string levels_path;
204 typedef std::vector<SpecialTile> SpecialTiles;
205 SpecialTiles special_tiles;
206 typedef std::vector<Level> Levels;
208 typedef std::vector<SpawnPoint*> SpawnPoints;
209 SpawnPoints spawn_points;
212 std::string savegame_file;
214 std::string intro_script;
215 bool intro_displayed;
217 void get_level_title(Level& level);
219 void draw_status(DrawingContext& context);
221 // to avoid calculating total stats all the time. This way only
222 // when need, it is calculated.
223 Statistics total_stats;
224 void calculate_total_stats();
232 void add_object(GameObject* object);
233 void clear_objects();
235 static WorldMap* current()
240 /** Update Tux position */
241 void update(float delta);
243 /** Draw one frame */
244 void draw(DrawingContext& context);
246 Vector get_next_tile(Vector pos, Direction direction);
247 const Tile* at(Vector pos);
250 * gets called from the GameSession when a level has been successfully
253 void finished_level(const std::string& filename);
255 WorldMap::Level* at_level();
256 WorldMap::SpecialTile* at_special_tile();
258 /** Check if it is possible to walk from \a pos into \a direction,
259 if possible, write the new position to \a new_pos */
260 bool path_ok(Direction direction, Vector pos, Vector* new_pos);
262 /* Save map to slot */
263 void savegame(const std::string& filename);
264 /* Load map from slot
265 You should call set_map_filename() before this */
266 void loadgame(const std::string& filename);
267 /* Load map directly from file */
268 void loadmap(const std::string& filename);
270 const std::string& get_world_title() const
273 void set_map_filename(std::string filename)
274 { map_filename = filename; }
277 void on_escape_press();
278 void parse_special_tile(const lisp::Lisp* lisp);
279 void parse_level_tile(const lisp::Lisp* lisp);
282 } // namespace WorldMapNS
286 /* Local Variables: */