-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevel.cpp
40 lines (30 loc) · 1.07 KB
/
Level.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "Level.h"
#include "TinyXML/tinyxml.h"
#include <iostream>
#define DEBUG 1
bool Level::Load(const std::string& filename)
{
TiXmlDocument levelFile(filename.c_str());
// Загружаем XML-карту
if(!levelFile.LoadFile())
{
std::cout << "Loading level \"" << filename << "\" failed." << std::endl;
return false;
}
const TiXmlElement* map = levelFile.FirstChildElement("map");
// TODO: Add check for map version
// Пример карты: <map version="1.0" orientation="orthogonal"
// width="10" height="10" tilewidth="34" tileheight="34">
map->Attribute(std::string("width"), &width);
map->Attribute(std::string("height"), &height);
map->Attribute(std::string("tilewidth"), &tileWidth);
const std::string* s = map->Attribute(std::string("tileheight"));
tileHeight = std::stoi(*s);
#ifdef DEBUG
std::cout << "width: " << width << std::endl;
std::cout << "height: " << height << std::endl;
std::cout << "tile width: " << tileWidth << std::endl;
std::cout << "tile height: " << tileHeight << std::endl;
#endif
return true;
}