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 "statistics.h"
31 #include "tile_manager.h"
37 extern Menu* worldmap_menu;
39 namespace WorldMapNS {
41 enum WorldMapMenuIDs {
55 enum Direction { D_NONE, D_WEST, D_EAST, D_NORTH, D_SOUTH };
57 std::string direction_to_string(Direction d);
58 Direction string_to_direction(const std::string& d);
59 Direction reverse_dir(Direction d);
66 Direction back_direction;
69 Surface* largetux_sprite;
70 Surface* firetux_sprite;
71 Surface* smalltux_sprite;
73 Direction input_direction;
76 /** Length by which tux is away from its current tile, length is in
77 input_direction direction */
83 Tux(WorldMap* worldmap_);
86 void draw(DrawingContext& context, const Vector& offset);
87 void action(float elapsed_time);
89 void set_direction(Direction dir);
91 bool is_moving() const { return moving; }
93 Vector get_tile_pos() const { return tile_pos; }
94 void set_tile_pos(Vector p) { tile_pos = p; }
105 Surface* leveldot_green;
106 Surface* leveldot_red;
108 Surface* teleporterdot;
113 std::vector<int> tilemap;
120 TileManager* tile_manager;
127 /** Optional flags: */
129 /** Position to swap to player */
130 Vector teleport_dest;
132 /** Message to show in the Map */
133 std::string map_message;
134 bool passive_message;
136 /** Hide special tile */
139 /** Only applies actions (ie. passive messages) when going to that direction */
140 bool apply_action_north;
141 bool apply_action_east;
142 bool apply_action_south;
143 bool apply_action_west;
154 /** Statistics for level tiles */
155 Statistics statistics;
157 /** Optional flags: */
159 /** Check if this level should be vertically flipped */
162 /** Filename of the extro text to show once the level is
163 successfully completed */
164 std::string extro_filename;
166 /** Go to this world */
167 std::string next_worldmap;
169 /** Quit the worldmap */
172 /** If false, disables the auto walking after finishing a level */
175 // Directions which are walkable from this level
182 /** Variables to deal with the passive map messages */
183 Timer2 passive_message_timer;
184 std::string passive_message;
187 std::string map_filename;
189 typedef std::vector<SpecialTile> SpecialTiles;
190 SpecialTiles special_tiles;
192 typedef std::vector<Level> Levels;
200 std::string savegame_file;
202 void get_level_title(Level& level);
204 void draw_status(DrawingContext& context);
206 // to avoid calculating total stats all the time. This way only
207 // when need, it is calculated.
208 Statistics total_stats;
209 void calculate_total_stats();
222 /** Update Tux position */
223 void update(float delta);
225 /** Draw one frame */
226 void draw(DrawingContext& context, const Vector& offset);
228 Vector get_next_tile(Vector pos, Direction direction);
229 const Tile* at(Vector pos);
231 WorldMap::Level* at_level();
232 WorldMap::SpecialTile* at_special_tile();
234 /** Check if it is possible to walk from \a pos into \a direction,
235 if possible, write the new position to \a new_pos */
236 bool path_ok(Direction direction, Vector pos, Vector* new_pos);
238 /* Save map to slot */
239 void savegame(const std::string& filename);
240 /* Load map from slot
241 You should call set_map_filename() before this */
242 void loadgame(const std::string& filename);
243 /* Load map directly from file */
244 void loadmap(const std::string& filename);
246 const std::string& get_world_title() const
249 const int& get_start_x() const
252 const int& get_start_y() const
255 void set_map_filename(std::string filename)
256 { map_filename = filename; }
259 void on_escape_press();
260 void parse_special_tiles(const lisp::Lisp* lisp);
263 } // namespace WorldMapNS
267 /* Local Variables: */