17 #ifndef HEADER_SUPERTUX_OBJECT_TILEMAP_HPP 18 #define HEADER_SUPERTUX_OBJECT_TILEMAP_HPP 21 #include <unordered_set> 23 #include "math/rect.hpp" 24 #include "math/rectf.hpp" 25 #include "math/size.hpp" 26 #include "object/path_object.hpp" 27 #include "object/path_walker.hpp" 28 #include "supertux/autotile.hpp" 29 #include "supertux/game_object.hpp" 30 #include "video/color.hpp" 31 #include "video/flip.hpp" 32 #include "video/drawing_target.hpp" 53 static void register_class(ssq::VM& vm);
62 static std::string class_name() {
return "tilemap"; }
63 virtual std::string get_class_name()
const override {
return class_name(); }
64 virtual std::string get_exposed_class_name()
const override {
return "TileMap"; }
65 virtual const std::string get_icon_path()
const override {
return "images/engine/editor/tilemap.png"; }
66 static std::string display_name() {
return _(
"Tilemap"); }
71 virtual void after_editor_set()
override;
74 void check_state()
override;
76 virtual void update(
float dt_sec)
override;
81 virtual void on_flip(
float height)
override;
83 void set(
int width,
int height,
const std::vector<unsigned int>& vec,
84 int z_pos,
bool solid);
88 void resize(
int newwidth,
int newheight,
int fill_id = 0,
89 int xoffset = 0,
int yoffset = 0);
92 int get_width()
const {
return m_width; }
93 int get_height()
const {
return m_height; }
94 Size get_size()
const {
return Size(m_width, m_height); }
96 void set_offset(
const Vector &offset_) { m_offset = offset_; }
97 Vector get_offset()
const {
return m_offset; }
99 void set_ground_movement_manager(
const std::shared_ptr<CollisionGroundMovementManager>& movement_manager)
101 m_ground_movement_manager = movement_manager;
104 void move_by(
const Vector& pos);
116 return Vector(m_movement.x, std::max(0.0f, m_movement.y));
122 {
return m_offset + Vector(static_cast<float>(x), static_cast<float>(y)) * 32.0f; }
124 Rectf get_bbox()
const {
129 Rectf get_tile_bbox(
int x,
int y)
const {
143 int get_layer()
const {
return m_z_pos; }
144 void set_layer(
int layer) { m_z_pos = layer; }
146 bool is_solid()
const {
return m_real_solid && m_effective_solid; }
156 bool is_outside_bounds(
const Vector& pos)
const;
157 const Tile& get_tile(
int x,
int y)
const;
158 const Tile& get_tile_at(
const Vector& pos)
const;
184 void change(
int x,
int y, uint32_t newtile);
192 void change_at(
float x,
float y, uint32_t newtile);
193 void change_at(
const Vector& pos, uint32_t newtile);
200 void change_all(uint32_t oldtile, uint32_t newtile);
203 void autotile(
int x,
int y, uint32_t tile);
205 enum class AutotileCornerOperation {
217 void autotile_corner(
int x,
int y, uint32_t tile, AutotileCornerOperation op);
225 void set_flip(Flip flip) { m_flip = flip; }
226 Flip get_flip()
const {
return m_flip; }
235 void fade(
float alpha,
float time);
250 void tint_fade(
float time,
float red,
float green,
float blue,
float alpha);
252 Color get_current_tint()
const {
return m_current_tint; }
267 float get_target_alpha()
const {
return m_alpha; }
269 void set_tileset(
const TileSet* new_tileset);
271 const std::vector<uint32_t>& get_tiles()
const {
return m_tiles; }
274 void update_effective_solid(
bool update_manager =
true);
275 void float_channel(
float target,
float ¤t,
float remaining_time,
float dt_sec);
277 bool is_corner(uint32_t tile)
const;
279 void apply_offset_x(
int fill_id,
int xoffset);
280 void apply_offset_y(
int fill_id,
int yoffset);
283 bool m_editor_active;
288 typedef std::vector<uint32_t> Tiles;
295 bool m_effective_solid;
306 std::unordered_set<CollisionObject*> m_objects_hit_bottom;
308 std::shared_ptr<CollisionGroundMovementManager> m_ground_movement_manager;
312 float m_current_alpha;
313 float m_remaining_fade_time;
319 Color m_current_tint;
320 float m_remaining_tint_fade_time;
323 DrawingTarget m_draw_target;
void change_at(float x, float y, uint32_t newtile)
Changes the tile at the given position (in-world coordinates) to ""newtile"".
Definition: tilemap.cpp:704
uint32_t get_tile_id(int x, int y) const
Returns the ID of the tile at the given coordinates or 0 if out of bounds.
Definition: tilemap.cpp:636
void autotile_corner(int x, int y, uint32_t tile, AutotileCornerOperation op)
Puts the correct autotile blocks at the tiles around the given corner.
Definition: tilemap.cpp:771
virtual GameObjectClasses get_class_types() const override
List notable classes in inheritance hierarchy of class.
Definition: tilemap.hpp:68
virtual void finish_construction() override
Called after all objects have been added to the Sector and the Sector is fully constructed.
Definition: tilemap.cpp:196
void change(int x, int y, uint32_t newtile)
Changes the tile at the given coordinates to ""newtile"".
Definition: tilemap.cpp:688
Definition: object_settings.hpp:39
Vector get_tile_position(int x, int y) const
Returns the position of the upper-left corner of tile (x, y) in the sector.
Definition: tilemap.hpp:121
This class takes care of moving objects that have collided on top of other moving objects or on top o...
Definition: collision_movement_manager.hpp:32
virtual void update(float dt_sec) override
This function is called once per frame and allows the object to update it's state.
Definition: tilemap.cpp:346
void save_state() override
Save/check the current state of the object.
Definition: tilemap.cpp:332
Vector get_movement(bool actual) const
Get the movement of this tilemap.
Definition: tilemap.hpp:110
void tint_fade(const Color &new_tint, float time=0.f)
Start fading the tilemap to tint given by RGBA.
Definition: tilemap.cpp:920
This class is responsible for: Updating and drawing the object.
Definition: game_object.hpp:83
void resize(int newwidth, int newheight, int fill_id=0, int xoffset=0, int yoffset=0)
resizes the tilemap to a new width and height (tries to not destroy the existing map) ...
Definition: tilemap.cpp:552
void set_solid(bool solid=true)
Switches the tilemap's real solidity to ""solid"".
Definition: tilemap.cpp:629
void change_all(uint32_t oldtile, uint32_t newtile)
Changes all tiles with the given ID.
Definition: tilemap.cpp:710
void hits_object_bottom(CollisionObject &object)
Called by the collision mechanism to indicate that this tilemap has been hit on the top...
Definition: tilemap.cpp:617
void autotile_erase(const Vector &pos, const Vector &corner_pos)
Erases in autotile mode.
Definition: tilemap.cpp:829
virtual void on_flip(float height) override
When level is flipped vertically.
Definition: tilemap.cpp:418
float get_alpha() const
Returns the tilemap's opacity.
Definition: tilemap.cpp:942
uint32_t get_tile_id_at(float x, float y) const
Returns the ID of the tile at the given position (in world coordinates).
Definition: tilemap.cpp:675
void autotile(int x, int y, uint32_t tile)
Puts the correct autotile block at the given position.
Definition: tilemap.cpp:723
Rect get_tiles_overlapping(const Rectf &rect) const
Returns the half-open rectangle of (x, y) tile indices that overlap the given rectangle in the sector...
Definition: tilemap.cpp:604
virtual GameObjectClasses get_class_types() const
List notable classes in inheritance hierarchy of class.
Definition: game_object.cpp:113
A base class for all objects that contain, or make use of a path.
Definition: path_object.hpp:36
A helper structure to list all the type_indexes of the classes in the type hierarchy of a given class...
Definition: game_object.hpp:57
virtual std::string get_display_name() const override
Returns the display name of the object, translated to the user's locale.
Definition: tilemap.hpp:67
void fade(float alpha, float time)
Starts fading the tilemap to the opacity given by ""alpha"".
Definition: tilemap.cpp:913
void set_alpha(float alpha)
Instantly switches the tilemap's opacity to ""alpha"".
Definition: tilemap.cpp:933
Definition: collision_object.hpp:33
AutotileSet * get_autotileset(uint32_t tile) const
Returns the Autotileset associated with the given tile.
Definition: tilemap.cpp:907
This class is responsible for managing an array of tiles.
Definition: tilemap.hpp:49
Definition: reader_mapping.hpp:32
Definition: tile_set.hpp:44
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42
Definition: autotile.hpp:79
virtual void draw(DrawingContext &context) override
The GameObject should draw itself onto the provided DrawingContext if this function is called...
Definition: tilemap.cpp:438
virtual void editor_update() override
Called each frame in the editor, used to keep linked objects together (e.g.
Definition: tilemap.cpp:396