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"
32 #include "tile_manager.hpp"
33 #include "game_object.hpp"
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 bool canWalk(const Tile* tile, Direction dir); /**< check if we can leave "tile" in direction "dir" */
86 void updateInputDirection(); /**< if controller was pressed, update input_direction */
87 void tryStartWalking(); /**< try starting to walk in input_direction */
88 void tryContinueWalking(float elapsed_time); /**< try to continue walking in current direction */
91 Tux(WorldMap* worldmap_);
94 void draw(DrawingContext& context);
95 void update(float elapsed_time);
97 void set_direction(Direction dir);
99 bool is_moving() const { return moving; }
101 Vector get_tile_pos() const { return tile_pos; }
102 void set_tile_pos(Vector p) { tile_pos = p; }
113 Surface* leveldot_green;
114 Surface* leveldot_red;
116 Sprite* teleporterdot;
121 typedef std::vector<GameObject*> GameObjects;
122 GameObjects game_objects;
125 TileManager* tile_manager;
132 /** Optional flags: */
134 /** Sprite to render instead of guessing what image to draw */
137 /** Position to swap to player */
138 Vector teleport_dest;
140 /** Message to show in the Map */
141 std::string map_message;
142 bool passive_message;
144 /** Hide special tile */
147 /** Only applies actions (ie. passive messages) when going to that direction */
148 bool apply_action_north;
149 bool apply_action_east;
150 bool apply_action_south;
151 bool apply_action_west;
164 /** Statistics for level tiles */
165 Statistics statistics;
167 /** Optional flags: */
169 /** Check if this level should be vertically flipped */
172 /** Script that is run when the level is successfully finished */
173 std::string extro_script;
175 /** Go to this world */
176 std::string next_worldmap;
178 /** Quit the worldmap */
181 /** If false, disables the auto walking after finishing a level */
184 // Directions which are walkable from this level
191 /** Variables to deal with the passive map messages */
192 Timer passive_message_timer;
193 std::string passive_message;
196 std::string map_filename;
197 std::string levels_path;
199 typedef std::vector<SpecialTile> SpecialTiles;
200 SpecialTiles special_tiles;
201 typedef std::vector<Level> Levels;
203 typedef std::vector<SpawnPoint*> SpawnPoints;
204 SpawnPoints spawn_points;
207 std::string savegame_file;
209 std::string intro_script;
210 bool intro_displayed;
212 void get_level_title(Level& level);
214 void draw_status(DrawingContext& context);
216 // to avoid calculating total stats all the time. This way only
217 // when need, it is calculated.
218 Statistics total_stats;
219 void calculate_total_stats();
232 void add_object(GameObject* object);
233 void clear_objects();
235 /** Update Tux position */
236 void update(float delta);
238 /** Draw one frame */
239 void draw(DrawingContext& context);
241 Vector get_next_tile(Vector pos, Direction direction);
242 const Tile* at(Vector pos);
244 WorldMap::Level* at_level();
245 WorldMap::SpecialTile* at_special_tile();
247 /** Check if it is possible to walk from \a pos into \a direction,
248 if possible, write the new position to \a new_pos */
249 bool path_ok(Direction direction, Vector pos, Vector* new_pos);
251 /* Save map to slot */
252 void savegame(const std::string& filename);
253 /* Load map from slot
254 You should call set_map_filename() before this */
255 void loadgame(const std::string& filename);
256 /* Load map directly from file */
257 void loadmap(const std::string& filename);
259 const std::string& get_world_title() const
262 void set_map_filename(std::string filename)
263 { map_filename = filename; }
266 void on_escape_press();
267 void parse_special_tile(const lisp::Lisp* lisp);
268 void parse_level_tile(const lisp::Lisp* lisp);
271 } // namespace WorldMapNS
275 /* Local Variables: */