添加waypoing dat

This commit is contained in:
aozhiwei 2019-06-01 17:40:13 +08:00
parent 366eeab683
commit c8007e81dd
2 changed files with 95 additions and 85 deletions

View File

@ -30,7 +30,7 @@ namespace f8
return itr != prop_hash.end();
}
bool TiledMap::LoadTmxFile(const std::string& filename)
bool TiledMap::LoadTmxFile(const std::string& filename, bool new_tmx_format)
{
a8::XObject xobj;
if (!xobj.ReadFromXmlFile(filename)) {
@ -356,83 +356,87 @@ namespace f8
}
}
if (grid_all_list.empty()) {
return false;
}
{
bool has_index = false;
int index = 0;
for (auto& gc : grid_all_list) {
if (gc->x == old_pos_x && gc->y == old_pos_y) {
has_index = true;
break;
}
index++;
}
if (!has_index) {
if (grid_all_list.empty()) {
return false;
}
int grid_all_count = grid_all_list.size();
for (int i = index; i < grid_all_count-1; ++i) {
GridCell* gc_first = grid_all_list[i];
GridCell* gc_second = grid_all_list[i+1];
int speed = gc_first->speed;
int time_use = 0;
if (gc_second->x == gc_first->x) {
time_use = a8::XValue((((float)tile_height / speed)*1000));
} else if (gc_second->y == gc_first->y) {
time_use = a8::XValue((((float)tile_width / speed)*1000));
} else {
float width_pow = std::pow(tile_width,2.0);
float height_pow = std::pow(tile_height,2.0);
float value_sqrt = std::sqrt(width_pow+height_pow);
time_use = a8::XValue(((value_sqrt / speed)*1000));
{
bool has_index = false;
int index = 0;
for (auto& gc : grid_all_list) {
if (gc->x == old_pos_x && gc->y == old_pos_y) {
has_index = true;
break;
}
index++;
}
time_ms -= time_use;
curr_pos_x = gc_second->x;
curr_pos_y = gc_second->y;
if (time_ms < 0) {
return true;
if (!has_index) {
return false;
}
int grid_all_count = grid_all_list.size();
for (int i = index; i < grid_all_count-1; ++i) {
GridCell* gc_first = grid_all_list[i];
GridCell* gc_second = grid_all_list[i+1];
int speed = gc_first->speed;
int time_use = 0;
if (gc_second->x == gc_first->x) {
time_use = a8::XValue((((float)tile_height / speed)*1000));
} else if (gc_second->y == gc_first->y) {
time_use = a8::XValue((((float)tile_width / speed)*1000));
} else {
float width_pow = std::pow(tile_width,2.0);
float height_pow = std::pow(tile_height,2.0);
float value_sqrt = std::sqrt(width_pow+height_pow);
time_use = a8::XValue(((value_sqrt / speed)*1000));
}
time_ms -= time_use;
curr_pos_x = gc_second->x;
curr_pos_y = gc_second->y;
if (time_ms < 0) {
return true;
}
}
}
}
if (time_ms > 0) {
return true;
}
return false;
}
std::vector<GridCell*> TiledMap::SortGridList(std::vector<GridCell*>* grid_list, StagePoint* sp)
{
std::vector<GridCell*> grid_sort_list;
std::map<GridCell*, bool> grid_tag_hash;
int grid_list_count = grid_list->size();
int old_x = 0;
int old_y = 0;
for (auto& gc : *grid_list) {
grid_tag_hash[gc] = false;
}
for (auto& gc : *grid_list) {
if (gc->x == sp->x && gc->y == sp->y) {
grid_sort_list.push_back(gc);
old_x = gc->x;
old_y = gc->y;
grid_tag_hash[gc] = true;
if (time_ms > 0) {
return true;
}
return false;
}
for (int count = 1; count < grid_list_count; ++count) {
GridCell* gc_next = nullptr;
for (int i = 0; i < grid_list_count; ++i) {
GridCell* gc = grid_list->at(i);
for (int x = old_x-1; x <= old_x+1; ++x) {
for(int y = old_y-1; y <= old_y+1; ++y) {
if (gc->x == x && gc->y == y && !grid_tag_hash[gc]) {
grid_tag_hash[gc] = true;
gc_next = gc;
old_x = gc->x;
old_y = gc->y;
std::vector<GridCell*> TiledMap::SortGridList(std::vector<GridCell*>* grid_list, StagePoint* sp)
{
std::vector<GridCell*> grid_sort_list;
std::map<GridCell*, bool> grid_tag_hash;
int grid_list_count = grid_list->size();
int old_x = 0;
int old_y = 0;
for (auto& gc : *grid_list) {
grid_tag_hash[gc] = false;
}
for (auto& gc : *grid_list) {
if (gc->x == sp->x && gc->y == sp->y) {
grid_sort_list.push_back(gc);
old_x = gc->x;
old_y = gc->y;
grid_tag_hash[gc] = true;
}
}
for (int count = 1; count < grid_list_count; ++count) {
GridCell* gc_next = nullptr;
for (int i = 0; i < grid_list_count; ++i) {
GridCell* gc = grid_list->at(i);
for (int x = old_x-1; x <= old_x+1; ++x) {
for(int y = old_y-1; y <= old_y+1; ++y) {
if (gc->x == x && gc->y == y && !grid_tag_hash[gc]) {
grid_tag_hash[gc] = true;
gc_next = gc;
old_x = gc->x;
old_y = gc->y;
break;
}
}
if (gc_next != nullptr) {
break;
}
}
@ -441,25 +445,27 @@ std::vector<GridCell*> TiledMap::SortGridList(std::vector<GridCell*>* grid_list,
}
}
if (gc_next != nullptr) {
break;
grid_sort_list.push_back(gc_next);
}
}
if (gc_next != nullptr) {
grid_sort_list.push_back(gc_next);
}
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;
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;
}
}
}
}
}
void TiledMap::LoadWayPointsData()
{
}
}

View File

@ -60,7 +60,7 @@ namespace f8
int tile_rows = 0; //行
int tile_columns = 0; //列
bool LoadTmxFile(const std::string& filename);
bool LoadTmxFile(const std::string& filename, bool new_tmx_format = false);
std::list<TiledObject>* GetObjectGroup(const std::string& object_class_name);
void Dump();
void Init();
@ -76,6 +76,9 @@ namespace f8
//速度设置
void SetGridCellSpeedByAreaId(std::map<int,int>& area_speed_hash);//key:area_id value:speed
private:
void LoadWayPointsData();
private:
std::map<std::string, std::list<TiledLayer>> layer_hash;
std::map<std::string, std::list<TiledObject>> object_group_hash;
@ -86,5 +89,6 @@ namespace f8
std::vector<GridCell> grid_cell_list; //所有的格子数组 size = x * y
std::map<std::string, std::vector<GridCell>> grid_cell_hash; //key 11|2 坐标
std::map<std::string, std::vector<std::tuple<int, int>>> waypoint_hash_; //路点数据
};
}