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"
34 #include "console.hpp"
41 extern Menu* worldmap_menu;
43 namespace WorldMapNS {
45 enum WorldMapMenuIDs {
59 enum Direction { D_NONE, D_WEST, D_EAST, D_NORTH, D_SOUTH };
61 std::string direction_to_string(Direction d);
62 Direction string_to_direction(const std::string& d);
63 Direction reverse_dir(Direction d);
67 class Tux : public GameObject
70 Direction back_direction;
74 Controller* controller;
76 Direction input_direction;
79 /** Length by which tux is away from its current tile, length is in
80 input_direction direction */
86 bool canWalk(const Tile* tile, Direction dir); /**< check if we can leave "tile" in direction "dir" */
87 void updateInputDirection(); /**< if controller was pressed, update input_direction */
88 void tryStartWalking(); /**< try starting to walk in input_direction */
89 void tryContinueWalking(float elapsed_time); /**< try to continue walking in current direction */
92 Tux(WorldMap* worldmap_);
95 void draw(DrawingContext& context);
96 void update(float elapsed_time);
98 void set_direction(Direction dir);
100 bool is_moving() const { return moving; }
102 Vector get_tile_pos() const { return tile_pos; }
103 void set_tile_pos(Vector p) { tile_pos = p; }
114 Surface* leveldot_green;
115 Surface* leveldot_red;
117 Sprite* teleporterdot;
122 typedef std::vector<GameObject*> GameObjects;
123 GameObjects game_objects;
126 TileManager* tile_manager;
135 /** Optional flags: */
137 /** Sprite to render instead of guessing what image to draw */
140 /** Position to swap to player */
141 Vector teleport_dest;
143 /** Message to show in the Map */
144 std::string map_message;
145 bool passive_message;
147 /** Hide special tile */
150 /** Only applies actions (ie. passive messages) when going to that direction */
151 bool apply_action_north;
152 bool apply_action_east;
153 bool apply_action_south;
154 bool apply_action_west;
167 /** Statistics for level tiles */
168 Statistics statistics;
170 /** Optional flags: */
172 /** Check if this level should be vertically flipped */
175 /** Script that is run when the level is successfully finished */
176 std::string extro_script;
178 /** Go to this world */
179 std::string next_worldmap;
181 /** Quit the worldmap */
184 /** If false, disables the auto walking after finishing a level */
187 // Directions which are walkable from this level
194 /** Variables to deal with the passive map messages */
195 Timer passive_message_timer;
196 std::string passive_message;
199 std::string map_filename;
200 std::string levels_path;
202 typedef std::vector<SpecialTile> SpecialTiles;
203 SpecialTiles special_tiles;
204 typedef std::vector<Level> Levels;
206 typedef std::vector<SpawnPoint*> SpawnPoints;
207 SpawnPoints spawn_points;
210 std::string savegame_file;
212 std::string intro_script;
213 bool intro_displayed;
215 void get_level_title(Level& level);
217 void draw_status(DrawingContext& context);
219 // to avoid calculating total stats all the time. This way only
220 // when need, it is calculated.
221 Statistics total_stats;
222 void calculate_total_stats();
235 void add_object(GameObject* object);
236 void clear_objects();
238 /** Update Tux position */
239 void update(float delta);
241 /** Draw one frame */
242 void draw(DrawingContext& context);
244 Vector get_next_tile(Vector pos, Direction direction);
245 const Tile* at(Vector pos);
247 WorldMap::Level* at_level();
248 WorldMap::SpecialTile* at_special_tile();
250 /** Check if it is possible to walk from \a pos into \a direction,
251 if possible, write the new position to \a new_pos */
252 bool path_ok(Direction direction, Vector pos, Vector* new_pos);
254 /* Save map to slot */
255 void savegame(const std::string& filename);
256 /* Load map from slot
257 You should call set_map_filename() before this */
258 void loadgame(const std::string& filename);
259 /* Load map directly from file */
260 void loadmap(const std::string& filename);
262 const std::string& get_world_title() const
265 void set_map_filename(std::string filename)
266 { map_filename = filename; }
269 void on_escape_press();
270 void parse_special_tile(const lisp::Lisp* lisp);
271 void parse_level_tile(const lisp::Lisp* lisp);
274 } // namespace WorldMapNS
278 /* Local Variables: */