src/object/tilemap.hpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #ifndef HEADER_SUPERTUX_OBJECT_TILEMAP_HPP
00018 #define HEADER_SUPERTUX_OBJECT_TILEMAP_HPP
00019 
00020 #include <boost/shared_ptr.hpp>
00021 
00022 #include "object/path_walker.hpp"
00023 #include "supertux/game_object.hpp"
00024 #include "supertux/script_interface.hpp"
00025 #include "video/drawing_context.hpp"
00026 
00027 namespace lisp {
00028 class Lisp;
00029 }
00030 
00031 class Level;
00032 class TileManager;
00033 class Tile;
00034 class TileSet;
00035 
00039 class TileMap : public GameObject, 
00040                 public ScriptInterface
00041 {
00042 public:
00043   TileMap(const TileSet *tileset);
00044   TileMap(const Reader& reader);
00045   TileMap(const TileSet *tileset, std::string name, int z_pos, bool solid_,
00046           size_t width_, size_t height_);
00047   virtual ~TileMap();
00048 
00049   virtual void update(float elapsed_time);
00050   virtual void draw(DrawingContext& context);
00051 
00053   void goto_node(int node_no);
00054 
00056   void start_moving();
00057 
00059   void stop_moving();
00060 
00061   virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
00062   virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
00063 
00064   void set(int width, int height, const std::vector<unsigned int>& vec,
00065            int z_pos, bool solid);
00066 
00070   void resize(int newwidth, int newheight, int fill_id = 0);
00071 
00072   size_t get_width() const
00073   { return width; }
00074 
00075   size_t get_height() const
00076   { return height; }
00077 
00078   Vector get_offset() const
00079   { return offset; }
00080 
00084   Vector get_movement(bool actual) const
00085   {
00086     if(actual) {
00087       return movement;
00088     } else {
00089       return Vector(movement.x, std::max(0.0f,movement.y));
00090     }
00091   }
00092 
00093   boost::shared_ptr<Path> get_path()
00094   { return path; }
00095 
00096   boost::shared_ptr<PathWalker> get_walker()
00097   { return walker; }
00098 
00099   void set_offset(const Vector &offset)
00100   { this->offset = offset; }
00101 
00102   /* Returns the position of the upper-left corner of
00103    * tile (x, y) in the sector. */
00104   Vector get_tile_position(int x, int y) const
00105   { return offset + Vector(x,y) * 32; }
00106 
00107   Rectf get_bbox() const
00108   { return Rectf(get_tile_position(0, 0), get_tile_position(width, height)); }
00109 
00110   Rectf get_tile_bbox(int x, int y) const
00111   { return Rectf(get_tile_position(x, y), get_tile_position(x+1, y+1)); }
00112 
00113   /* Returns the half-open rectangle of (x, y) tile indices
00114    * that overlap the given rectangle in the sector. */
00115   Rect get_tiles_overlapping(const Rectf &rect) const;
00116 
00117   int get_layer() const
00118   { return z_pos; }
00119 
00120   bool is_solid() const
00121   { return real_solid && effective_solid; }
00122 
00126   void set_solid(bool solid = true);
00127 
00129   const Tile* get_tile(int x, int y) const;
00131   const Tile* get_tile_at(const Vector& pos) const;
00133   uint32_t get_tile_id(int x, int y) const;
00135   uint32_t get_tile_id_at(const Vector& pos) const;
00136 
00137   void change(int x, int y, uint32_t newtile);
00138 
00139   void change_at(const Vector& pos, uint32_t newtile);
00140 
00142   void change_all(uint32_t oldtile, uint32_t newtile);
00143 
00144   void set_drawing_effect(DrawingEffect effect)
00145   {
00146     drawing_effect = effect;
00147   }
00148 
00149   DrawingEffect get_drawing_effect()
00150   {
00151     return drawing_effect;
00152   }
00153 
00158   void fade(float alpha, float seconds = 0);
00159 
00163   void set_alpha(float alpha);
00164 
00168   float get_alpha();
00169 
00170 private:
00171   const TileSet *tileset;
00172 
00173   typedef std::vector<uint32_t> Tiles;
00174   Tiles tiles;
00175 
00176   /* read solid: In *general*, is this a solid layer?
00177    * effective solid: is the layer *currently* solid? A generally solid layer
00178    * may be not solid when its alpha is low.
00179    * See `is_solid' above. */
00180   bool real_solid;
00181   bool effective_solid;
00182   void update_effective_solid (void);
00183 
00184   float speed_x;
00185   float speed_y;
00186   int width, height;
00187   int z_pos;
00188   Vector offset;
00189   Vector movement; 
00191   DrawingEffect drawing_effect;
00192   float alpha; 
00193   float current_alpha; 
00194   float remaining_fade_time; 
00196   boost::shared_ptr<Path> path;
00197   boost::shared_ptr<PathWalker> walker;
00198 
00199   DrawingContext::Target draw_target; 
00201 private:
00202   TileMap(const TileMap&);
00203   TileMap& operator=(const TileMap&);
00204 };
00205 
00206 #endif /*SUPERTUX_TILEMAP_H*/
00207 
00208 /* EOF */

Generated on Mon Jun 9 03:38:20 2014 for SuperTux by  doxygen 1.5.1