From 91ffa8637cddddae07c42115788e5104a5faca7f Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Sat, 1 Feb 2025 23:19:16 +0500 Subject: feat: tile rotation --- src/floor.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/floor.cpp') diff --git a/src/floor.cpp b/src/floor.cpp index 8482b48..b8503ec 100644 --- a/src/floor.cpp +++ b/src/floor.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -16,6 +17,21 @@ namespace silly::editor { sf::Sprite s(t->tile->texture); s.setPosition({t->position.x * (float)TILE_WIDTH, t->position.y * (float)TILE_HEIGHT}); + s.setRotation(sf::degrees(t->rotation)); + + sf::Vector2f origin; + sf::Vector2u size = t->tile->texture.getSize(); + + if (t->rotation == 90.0f) { + origin.y = size.y; + } else if (t->rotation == 180.0f) { + origin.x = size.x; + origin.y = size.y; + } else if (t->rotation == 270.0f) { + origin.x = size.x; + } + + s.setOrigin(origin); window.draw(s); } @@ -23,13 +39,14 @@ namespace silly::editor { } void TileFloor::place_tile(std::shared_ptr &tile, - const sf::Vector2i &position) { + const sf::Vector2i &position, + const float &rotation) { TileLayer &layer = this->layers.at(tile->type); if (!std::any_of( layer.tiles.begin(), layer.tiles.end(), [&position](const Tile &t) { return t.position == position; })) { - layer.tiles.push_back({position, tile}); + layer.tiles.push_back({tile, position, rotation}); } } void TileFloor::remove_tile(const sf::Vector2i &position) { -- cgit v1.2.3