tiled地图速度配表

This commit is contained in:
songhao 2018-11-16 14:08:13 +08:00
parent 2dafab9662
commit d03f5c6957
2 changed files with 25 additions and 3 deletions

View File

@ -36,13 +36,15 @@ bool TiledMap::LoadTmxFile(const std::string& filename)
} }
std::shared_ptr<a8::XObject> tileset_node = xobj.At("child_node.tileset")->At(0); std::shared_ptr<a8::XObject> 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_width = tileset_node->At("attrs.tilewidth")->AsXValue();
tile_height = tileset_node->At("attrs.tileheight")->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_columns = tileset_node->At("attrs.columns")->AsXValue();
tile_rows = tile_count/tile_columns + 1; tile_rows = tile_count/tile_columns + 1;
tile_columns += 1; tile_columns += 1;
tile_count = tile_rows * tile_columns; tile_count = tile_rows * tile_columns;
#endif
for (int i = 0; i < xobj.At("child_node.layer")->Size(); ++i) { for (int i = 0; i < xobj.At("child_node.layer")->Size(); ++i) {
std::shared_ptr<a8::XObject> layer_node = xobj.At("child_node.layer")->At(i); std::shared_ptr<a8::XObject> 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(); 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); auto itr = layer_hash.find(layer_name);
if (itr != layer_hash.end()) { if (itr != layer_hash.end()) {
itr->second.push_back(layer); itr->second.push_back(layer);
@ -142,8 +149,8 @@ void TiledMap::Init()
for (auto& layer : pair.second) { for (auto& layer : pair.second) {
std::string name = layer.GetProperty("name").GetString(); std::string name = layer.GetProperty("name").GetString();
bool has_speed = layer.HasProperty("speed"); bool has_speed = layer.HasProperty("area_id");
int speed = layer.GetProperty("speed"); int speed = layer.GetProperty("area_id");
bool has_trigger = layer.HasProperty("isTrigger"); bool has_trigger = layer.HasProperty("isTrigger");
bool istrigger = layer.GetProperty("isTrigger");; bool istrigger = layer.GetProperty("isTrigger");;
@ -439,3 +446,15 @@ std::vector<GridCell*> TiledMap::SortGridList(std::vector<GridCell*>* grid_list,
} }
return grid_sort_list; return grid_sort_list;
} }
void TiledMap::SetGridCellSpeedByAreaId(std::map<int,int>& 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;
}
}
}
}

View File

@ -71,6 +71,9 @@ class TiledMap
std::vector<GridCell*> SortGridList(std::vector<GridCell*>* grid_list, StagePoint* sp); std::vector<GridCell*> SortGridList(std::vector<GridCell*>* grid_list, StagePoint* sp);
bool CalcCurrPos(std::vector<int>& path_points, int old_pos_x, int old_pos_y, int time_ms, int& curr_pos_x, int& curr_pos_y); bool CalcCurrPos(std::vector<int>& 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<int,int>& area_speed_hash);//key:area_id value:speed
private: private:
std::map<std::string, std::list<TiledLayer>> layer_hash; std::map<std::string, std::list<TiledLayer>> layer_hash;
std::map<std::string, std::list<TiledObject>> object_group_hash; std::map<std::string, std::list<TiledObject>> object_group_hash;