diff --git a/src/sagotmx/tmx_struct.h b/src/sagotmx/tmx_struct.h index 69bd8fc..79950c2 100644 --- a/src/sagotmx/tmx_struct.h +++ b/src/sagotmx/tmx_struct.h @@ -251,6 +251,7 @@ struct TileObject { int width = 0; int height = 0; bool isEcplise = false; + std::vector > polygon_points; }; struct TileObjectGroup { @@ -386,6 +387,26 @@ inline TileMap string2tilemap(const std::string& tmx_content) { setValueFromAttribute(object_node, "width", to.width); setValueFromAttribute(object_node, "height", to.height); getElement(object_node, "eclipse", to.isEcplise); + bool isPolygon = false; + const auto& polygon = getElement(object_node, "polygon", isPolygon); + if (isPolygon) { + std::string points; + setValueFromAttribute(polygon, "points", points); + size_t points_pos = 0; + size_t end_pos = 0; + while( points_pos < points.size() ) { + end_pos = points.find(",", points_pos); + int x = std::stoi(points.substr(points_pos, end_pos)); + points_pos = end_pos+1; + end_pos = points.find(" ", points_pos); + if (end_pos == std::string::npos) { + end_pos = points.size(); + } + int y = std::stoi(points.substr(points_pos, end_pos)); + points_pos = end_pos+1; + to.polygon_points.push_back(std::make_pair(x, y)); + } + } group.objects.push_back(to); } m.object_groups.push_back(group); diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 1b6218e..2268481 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -38,6 +38,13 @@ static void DrawOjbectGroup (SDL_Renderer* renderer, const sago::tiled::TileMap& for (const sago::tiled::TileObject& o : group.objects) { rectangleRGBA(renderer, o.x - topx, o.y - topy, o.x+o.width-topx, o.y + o.height - topy, 255, 255, 0, 255); + if (o.polygon_points.size() > 0) { + for (size_t i = 0; i < o.polygon_points.size(); ++i) { + std::pair first = o.polygon_points.at(i); + std::pair second = (i+1 < o.polygon_points.size()) ? o.polygon_points.at(i+1) : o.polygon_points.at(0); + lineRGBA(renderer, first.first +o.x - topx, first.second + o.y - topy, second.first + o.x - topx, second.second + o.y - topy, 255, 255, 0, 255); + } + } } }