f8/cpp/tiledmap.h
2019-06-01 19:13:46 +08:00

92 lines
2.6 KiB
C++

#pragma once
namespace f8
{
class TiledObject
{
public:
a8::XValue GetProperty(const std::string& prop_name);
bool HasProperty(const std::string& prop_name);
public:
std::map<std::string, a8::XValue> prop_hash;
};
class TiledLayer
{
public:
a8::XValue GetProperty(const std::string& prop_name);
bool HasProperty(const std::string& prop_name);
public:
std::map<std::string, a8::XValue> prop_hash;
a8::XValue data;
};
//格子对象
struct GridCell
{
int x = 0;
int y = 0;
int speed = 0;
int value = 0;
};
struct StagePoint
{
int x = 0;
int y = 0;
int point = 0;
std::vector<int> relation_list;
};
struct TriggerPoint
{
int x = 0;
int y = 0;
int point = 0;
bool istrigger = false;
};
class TiledMap
{
public:
TiledLayer* ground_layer = nullptr;
std::list<TiledLayer> speed_layers;
int tile_count = 0; //瓦片地图的尺寸。(以瓦片数量为单位)
int tile_width = 0; //瓦片的宽。(以像素点为单位)
int tile_height = 0; //瓦片的高。(以像素点为单位)
int tile_rows = 0; //行
int tile_columns = 0; //列
bool LoadTmxFile(const std::string& filename);
void LoadWayPointsData(const std::string& filename);
std::list<TiledObject>* GetObjectGroup(const std::string& object_class_name);
void Dump();
void Init();
StagePoint* GetStageObject(int point);
bool HasStageObject(int point);
std::vector<GridCell*>* GetStagePath(const std::string& path_name);
bool HasStagePath(const std::string& path_name);
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);
//速度设置
void SetGridCellSpeedByAreaId(std::map<int,int>& area_speed_hash);//key:area_id value:speed
private:
std::map<std::string, std::list<TiledLayer>> layer_hash;
std::map<std::string, std::list<TiledObject>> object_group_hash;
std::map<int, StagePoint> stage_object_hash; //key point
std::vector<TriggerPoint> trigger_list;
std::map<std::string, std::vector<GridCell*>> stage_path_hash; //key 11|2
std::vector<GridCell> grid_cell_list; //所有的格子数组 size = x * y
std::map<std::string, std::vector<GridCell>> grid_cell_hash; //key 11|2 坐标
};
}