diff --git a/Data/Map/Ugly.tmx b/Data/Map/Ugly.tmx index 54271b6..0444e8e 100644 --- a/Data/Map/Ugly.tmx +++ b/Data/Map/Ugly.tmx @@ -54,7 +54,14 @@ - eJztl0sOwyAMROn9L91NF1ZkiH9DTDNPYtG0eDxgQzoG6crnNyJz5HianT6sv43Ej/q46lnnoXx4NTI6Hh9XHQR3PuSzJ/pvNV/LTX7W4ng0rXl4YmZ9RDRX+pX9u8OHJQ9PTC3Pil6z1gvKRxWI+Hf9NZTvKzQ1nWxMa13urqtMzDHq12t2ViDqFtEHs9iV9w4Cq/5q/z1xkFhy6L4fXXKQePPRejd6b2WpyKFDjf+Dj8q6eHovZC7y2Ul49gO93jv2c8d7xIk+EBqeu5gQQggh72H2/rkaHYn8N+7IaT6q6iQyt6omUbUdWYOMFqoWsj66nC9e/ZPOP0LIO/kCOj8BWg== + eJztl8ESwyAIRJP//+leemA6oIC7BhvejIemlV0QNb2upir3d2TnZeYyyHi5lYHWYsaWc5ha2TpFNFZ0Inn86jCY5SGf7exbK8bMm/xs/darZ3lA1yGSR0ZzpI/cvzvy8PiIxNR8ovaaxxsrDxSM+LP9dSnfIzQ1ndWY6L70ajLy0OqP0rHOCkadGHW3YiPvHQZe/dH6R+Iw8Xiovh5VPEiifrS9m723VkF4qNDj/5AHsi+eXgvpRT47ich6sOu9Yz13vEecmAdDI3IXN03TNE3zHqz3z9GoSOa/cUVOywPVJ5m5qJ5k9XamBitarF5YzaPK+RLVP+n8a5rmnXwA7bUBUA== + + + + + + + diff --git a/src/Level/Level.cpp b/src/Level/Level.cpp index 63009f1..e2f7ffe 100644 --- a/src/Level/Level.cpp +++ b/src/Level/Level.cpp @@ -7,11 +7,15 @@ #include "../Sound/Music.h" #include "../System/Debug.h" #include "../TMXParser/Tmx.h" +#include "../Actor/NPC.h" #ifdef _WIN32 #ifndef strcasecmp #define strcasecmp stricmp #endif +#ifndef strncasecmp +#define strncasecmp strnicmp +#endif #endif Level::Level() { @@ -34,6 +38,11 @@ Level::~Level() { } _tilesets.clear(); + for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { + delete (*i); + } + _npcs.end(); + if(_collisions) { delete[] _collisions; _collisions = NULL; @@ -115,6 +124,19 @@ bool Level::Load(const std::string& filename) { _layers.push_back(layer); } + for(int i = 0; i < map.GetNumObjectGroups(); i++) { + const Tmx::ObjectGroup* tmxGroup = map.GetObjectGroup(i); + for(int j = 0; j < tmxGroup->GetNumObjects(); j++) { + const Tmx::Object* tmxObject = tmxGroup->GetObject(j); + if(!strncasecmp(tmxObject->GetName().c_str(), "NPC", 3)) { + NPC* npc = new NPC(this); + npc->LoadSprites(tmxObject->GetProperties().GetLiteralProperty("image").c_str()); + npc->SetXY(tmxObject->GetX(), tmxObject->GetY()); + _npcs.push_back(npc); + } + } + } + std::map mapProps = map.GetProperties().GetList(); for(std::map::iterator i = mapProps.begin(); i != mapProps.end(); ++i) { if(i->first == "BGM") { @@ -135,12 +157,18 @@ void Level::Update(float dt) { for(std::list::iterator i = _layers.begin(); i != _layers.end(); ++i) { (*i)->Update(dt); } + for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { + (*i)->Update(dt); + } } void Level::Draw(int xOffset, int yOffset) { for(std::list::iterator i = _layers.begin(); i != _layers.end(); ++i) { (*i)->Draw(xOffset, yOffset); } + for(std::list::iterator i = _npcs.begin(); i != _npcs.end(); ++i) { + (*i)->Render(); + } } bool Level::CheckCollision(float x, float y, float w, float h) const { diff --git a/src/Level/Level.h b/src/Level/Level.h index 3f09c6d..f3ddf8e 100644 --- a/src/Level/Level.h +++ b/src/Level/Level.h @@ -6,6 +6,7 @@ class Layer; class Tileset; class Music; +class NPC; class Level { public: @@ -33,6 +34,7 @@ private: int _tileHeight; std::list _layers; std::list _tilesets; + std::list _npcs; Music* _bgm; bool* _collisions; };