add tiledmap.*
This commit is contained in:
parent
1625d6a86b
commit
ef2c68bf65
41
cpp/tiledmap.cc
Normal file
41
cpp/tiledmap.cc
Normal file
@ -0,0 +1,41 @@
|
||||
#include <a8/a8.h>
|
||||
|
||||
#include "tiledmap.h"
|
||||
|
||||
a8::XValue TiledObject::GetProperty(const std::string& prop_name)
|
||||
{
|
||||
auto itr = prop_hash.find(prop_name);
|
||||
return itr == prop_hash.end() ? itr->second : a8::XValue();
|
||||
}
|
||||
|
||||
bool TiledObject::HasProperty(const std::string& prop_name)
|
||||
{
|
||||
auto itr = prop_hash.find(prop_name);
|
||||
return itr != prop_hash.end();
|
||||
}
|
||||
|
||||
|
||||
a8::XValue TiledLayer::GetProperty(const std::string& prop_name)
|
||||
{
|
||||
auto itr = prop_hash.find(prop_name);
|
||||
return itr != prop_hash.end() ? itr->second : a8::XValue();
|
||||
}
|
||||
|
||||
bool TiledLayer::HasProperty(const std::string& prop_name)
|
||||
{
|
||||
auto itr = prop_hash.find(prop_name);
|
||||
return itr != prop_hash.end();
|
||||
}
|
||||
|
||||
bool TiledMap::LoadTmxFile(const std::string& filename)
|
||||
{
|
||||
a8::XObject xobj;
|
||||
xobj.ReadFromXmlFile(filename);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::list<TiledObject>* TiledMap::GetObjectGroup(const std::string& object_class_name)
|
||||
{
|
||||
auto itr = object_group_hash.find(object_class_name);
|
||||
return itr != object_group_hash.end() ? &itr->second : nullptr;
|
||||
}
|
38
cpp/tiledmap.h
Normal file
38
cpp/tiledmap.h
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
class TiledObject
|
||||
{
|
||||
public:
|
||||
a8::XValue GetProperty(const std::string& prop_name);
|
||||
bool HasProperty(const std::string& prop_name);
|
||||
|
||||
private:
|
||||
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);
|
||||
|
||||
private:
|
||||
std::map<std::string, a8::XValue> prop_hash;
|
||||
};
|
||||
|
||||
class TiledMap
|
||||
{
|
||||
public:
|
||||
TiledLayer* ground_layer = nullptr;
|
||||
std::list<TiledLayer> speed_layers;
|
||||
int map_size = 0; //瓦片地图的尺寸。(以瓦片数量为单位)
|
||||
int tile_size = 0; //瓦片的尺寸。(以像素点为单位)
|
||||
|
||||
bool LoadTmxFile(const std::string& filename);
|
||||
std::list<TiledObject>* GetObjectGroup(const std::string& object_class_name);
|
||||
|
||||
private:
|
||||
std::map<std::string, std::list<TiledObject>> object_group_hash;
|
||||
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user