From d03f5c695730d195948f2fca682d2495b16befef Mon Sep 17 00:00:00 2001 From: songhao Date: Fri, 16 Nov 2018 14:08:13 +0800 Subject: [PATCH] =?UTF-8?q?tiled=E5=9C=B0=E5=9B=BE=E9=80=9F=E5=BA=A6?= =?UTF-8?q?=E9=85=8D=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cpp/tiledmap.cc | 25 ++++++++++++++++++++++--- cpp/tiledmap.h | 3 +++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/cpp/tiledmap.cc b/cpp/tiledmap.cc index ab77e87..52809d3 100644 --- a/cpp/tiledmap.cc +++ b/cpp/tiledmap.cc @@ -36,13 +36,15 @@ bool TiledMap::LoadTmxFile(const std::string& filename) } std::shared_ptr tileset_node = xobj.At("child_node.tileset")->At(0); - tile_count = tileset_node->At("attrs.tilecount")->AsXValue(); tile_width = tileset_node->At("attrs.tilewidth")->AsXValue(); tile_height = tileset_node->At("attrs.tileheight")->AsXValue(); + #if 0 + tile_count = tileset_node->At("attrs.tilecount")->AsXValue(); tile_columns = tileset_node->At("attrs.columns")->AsXValue(); tile_rows = tile_count/tile_columns + 1; tile_columns += 1; tile_count = tile_rows * tile_columns; + #endif for (int i = 0; i < xobj.At("child_node.layer")->Size(); ++i) { std::shared_ptr layer_node = xobj.At("child_node.layer")->At(i); @@ -63,6 +65,11 @@ bool TiledMap::LoadTmxFile(const std::string& filename) } std::string layer_name = layer_node->At("attrs.name")->AsXValue(); + if (layer_name.compare("ground") == 0) { + tile_columns = layer_node->At("attrs.width")->AsXValue(); + tile_rows = layer_node->At("attrs.height")->AsXValue(); + tile_count = tile_rows * tile_columns; + } auto itr = layer_hash.find(layer_name); if (itr != layer_hash.end()) { itr->second.push_back(layer); @@ -142,8 +149,8 @@ void TiledMap::Init() for (auto& layer : pair.second) { std::string name = layer.GetProperty("name").GetString(); - bool has_speed = layer.HasProperty("speed"); - int speed = layer.GetProperty("speed"); + bool has_speed = layer.HasProperty("area_id"); + int speed = layer.GetProperty("area_id"); bool has_trigger = layer.HasProperty("isTrigger"); bool istrigger = layer.GetProperty("isTrigger");; @@ -439,3 +446,15 @@ std::vector TiledMap::SortGridList(std::vector* grid_list, } return grid_sort_list; } + +void TiledMap::SetGridCellSpeedByAreaId(std::map& area_speed_hash) +{ + for (auto& pair : stage_path_hash) { + for (auto& grid_cell : pair.second) { + auto itr = area_speed_hash.find(grid_cell->speed); + if (itr != area_speed_hash.end()) { + grid_cell->speed = itr->second; + } + } + } +} diff --git a/cpp/tiledmap.h b/cpp/tiledmap.h index 7fda64e..b6d2ec4 100644 --- a/cpp/tiledmap.h +++ b/cpp/tiledmap.h @@ -71,6 +71,9 @@ class TiledMap std::vector SortGridList(std::vector* grid_list, StagePoint* sp); bool CalcCurrPos(std::vector& path_points, int old_pos_x, int old_pos_y, int time_ms, int& curr_pos_x, int& curr_pos_y); + //速度设置 + void SetGridCellSpeedByAreaId(std::map& area_speed_hash);//key:area_id value:speed + private: std::map> layer_hash; std::map> object_group_hash;