1 /* 2 * Copyright (C) 2006-2019 Christopho, Solarus - http://www.solarus-games.org 3 * 4 * Solarus is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * Solarus is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 #ifndef SOLARUS_TILE_H 18 #define SOLARUS_TILE_H 19 20 #include "solarus/core/Common.h" 21 #include "solarus/entities/Entity.h" 22 #include "solarus/graphics/SurfacePtr.h" 23 #include <string> 24 25 namespace Solarus { 26 27 struct TileInfo; 28 class Tileset; 29 class TilePattern; 30 31 /** 32 * \brief A small fixed piece of the map, optimized for collisions and drawing. 33 * 34 * A tile is composed of a tile pattern that can be repeated. 35 * Its pattern may be animated. It can be an obstacle or not. 36 * 37 * Tiles are optimized to allow fast detection of obstacles and 38 * fast rendering of the non-animated ones. 39 * The cost of these optimizations is that their presence on the map, their 40 * position, their size and their obstacle property are fixed. 41 * Tiles are added when the map is loaded and they are removed when the map 42 * is destroyed. 43 * 44 * If you need to dynamically enable or disable a tile, see DynamicTile. 45 */ 46 class Tile: public Entity { 47 48 public: 49 50 static constexpr EntityType ThisType = EntityType::TILE; 51 52 Tile(const TileInfo& tile_info); 53 54 EntityType get_type() const override; 55 bool is_drawn_at_its_position() const override; 56 void built_in_draw(Camera& camera) override; 57 void draw_on_surface(const SurfacePtr& dst_surface, const Point& viewport); 58 void notify_tileset_changed() override; 59 const TilePattern& get_tile_pattern() const; 60 const std::string& get_tile_pattern_id() const; 61 bool is_animated() const; 62 63 private: 64 65 const std::string tile_pattern_id; /**< Id of the tile pattern. */ 66 std::shared_ptr<TilePattern> 67 tile_pattern; /**< Pattern of the tile, or nullptr if it does not exist. */ 68 const Tileset* tileset; /**< Tileset of the pattern (nullptr means the one of the map). */ 69 70 }; 71 72 } 73 74 #endif 75 76