src/worldmap/worldmap.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
00003 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
00004 //
00005 //  This program is free software: you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation, either version 3 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program is distributed in the hope that it will be useful,
00011 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License
00016 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 #ifndef HEADER_SUPERTUX_WORLDMAP_WORLDMAP_HPP
00019 #define HEADER_SUPERTUX_WORLDMAP_WORLDMAP_HPP
00020 
00021 #include <string>
00022 #include <vector>
00023 
00024 #include "control/controller.hpp"
00025 #include "util/reader_fwd.hpp"
00026 #include "math/vector.hpp"
00027 #include "supertux/console.hpp"
00028 #include "supertux/game_object.hpp"
00029 #include "supertux/level.hpp"
00030 #include "supertux/screen.hpp"
00031 #include "supertux/statistics.hpp"
00032 #include "supertux/tile_manager.hpp"
00033 #include "supertux/timer.hpp"
00034 #include "worldmap/direction.hpp"
00035 #include "worldmap/spawn_point.hpp"
00036 #include "worldmap/special_tile.hpp"
00037 #include "worldmap/sprite_change.hpp"
00038 #include "worldmap/teleporter.hpp"
00039 
00040 class Sprite;
00041 class Menu;
00042 class GameObject;
00043 class TileMap;
00044 class PlayerStatus;
00045 
00046 namespace worldmap {
00047 
00048 class Tux;
00049 class LevelTile;
00050 class SpecialTile;
00051 class SpriteChange;
00052 
00053 // For one way tiles
00054 enum {
00055   BOTH_WAYS,
00056   NORTH_SOUTH_WAY,
00057   SOUTH_NORTH_WAY,
00058   EAST_WEST_WAY,
00059   WEST_EAST_WAY
00060 };
00061 
00065 class WorldMap : public Screen
00066 {
00067   static Color level_title_color;
00068   static Color message_color;
00069   static Color teleporter_message_color;
00070 
00071 private:
00072   typedef std::vector<SpecialTile*> SpecialTiles;
00073   typedef std::vector<SpriteChange*> SpriteChanges;
00074   typedef std::vector<SpawnPoint*> SpawnPoints;
00075   typedef std::vector<LevelTile*> LevelTiles;
00076   typedef std::vector<GameObject*> GameObjects;
00077   typedef std::vector<HSQOBJECT> ScriptList;
00078 
00079   Tux* tux;
00080 
00081   PlayerStatus* player_status;
00082 
00083   TileSet *tileset;
00084   bool     free_tileset;
00085 
00086   static WorldMap* current_;
00087 
00088   std::auto_ptr<Menu> worldmap_menu;
00089 
00090   Vector camera_offset;
00091 
00092   std::string name;
00093   std::string music;
00094   std::string init_script;
00095 
00096   GameObjects game_objects;
00097   std::list<TileMap*> solid_tilemaps;
00098 
00099 public:
00101   Timer passive_message_timer;
00102   std::string passive_message;
00103 
00104 private:
00105   std::string map_filename;
00106   std::string levels_path;
00107 
00108   SpecialTiles special_tiles;
00109   LevelTiles levels;
00110   SpriteChanges sprite_changes;
00111   SpawnPoints spawn_points;
00112   std::vector<Teleporter*> teleporters;
00113 
00114   Statistics total_stats;
00115 
00116   HSQOBJECT worldmap_table;
00117   ScriptList scripts;
00118 
00119   Color ambient_light;
00120   std::string force_spawnpoint; 
00122   bool in_level;
00123 
00124   /* variables to track panning to a spawn point */
00125   Vector pan_pos;
00126   bool panning;
00127 
00128 public:
00129   WorldMap(const std::string& filename, PlayerStatus* player_status, const std::string& force_spawnpoint = "");
00130   ~WorldMap();
00131 
00132   void add_object(GameObject* object);
00133   
00134   void try_expose(GameObject* object);
00135   void try_unexpose(GameObject* object);
00136 
00137   static WorldMap* current()
00138   { return current_; }
00139 
00140   virtual void setup();
00141   virtual void leave();
00142 
00144   virtual void update(float delta);
00146   virtual void draw(DrawingContext& context);
00147 
00148   Vector get_next_tile(Vector pos, Direction direction);
00149 
00154   int available_directions_at(Vector pos);
00155 
00160   int tile_data_at(Vector pos);
00161 
00162   size_t level_count();
00163   size_t solved_level_count();
00164 
00169   void finished_level(Level* level);
00170 
00172   Tux* get_tux() { return tux; }
00173 
00175   PlayerStatus* get_player_status() { return player_status; }
00176 
00177   LevelTile* at_level();
00178   SpecialTile* at_special_tile();
00179   SpriteChange* at_sprite_change(const Vector& pos);
00180   Teleporter* at_teleporter(const Vector& pos);
00181 
00184   bool path_ok(Direction direction, const Vector& pos, Vector* new_pos);
00185 
00189   void save_state();
00190 
00194   void load_state();
00195 
00196   const std::string& get_title() const
00197   { return name; }
00198 
00203   HSQUIRRELVM run_script(std::istream& in, const std::string& sourcename);
00204 
00209   void change(const std::string& filename, const std::string& force_spawnpoint="");
00210 
00214   void move_to_spawnpoint(const std::string& spawnpoint, bool pan =false);
00215 
00219   float get_width() const;
00220 
00224   float get_height() const;
00225 
00226 private:
00227   void get_level_title(LevelTile& level);
00228   void draw_status(DrawingContext& context);
00229   void calculate_total_stats();
00230 
00231   void load(const std::string& filename);
00232   void on_escape_press();
00233 
00234   Vector get_camera_pos_for_tux();
00235   void clamp_camera_position(Vector& c);
00236 
00237 private:
00238   WorldMap(const WorldMap&);
00239   WorldMap& operator=(const WorldMap&);
00240 };
00241 
00242 } // namespace worldmap
00243 
00244 #endif
00245 
00246 /* EOF */

Generated on Mon Apr 21 03:38:19 2014 for SuperTux by  doxygen 1.5.1