[Add] Adding NPCs through Tiled.
This commit is contained in:
parent
b20b5414c7
commit
efb695e973
@ -54,7 +54,14 @@
|
||||
</layer>
|
||||
<layer name="Collision" width="50" height="50">
|
||||
<data encoding="base64" compression="zlib">
|
||||
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==
|
||||
</data>
|
||||
</layer>
|
||||
<objectgroup name="NPCs" width="50" height="50">
|
||||
<object name="NPC!!!" type="NPC" x="544" y="320" width="32" height="32">
|
||||
<properties>
|
||||
<property name="image" value="Player"/>
|
||||
</properties>
|
||||
</object>
|
||||
</objectgroup>
|
||||
</map>
|
||||
|
@ -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<NPC*>::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<std::string, std::string> mapProps = map.GetProperties().GetList();
|
||||
for(std::map<std::string, std::string>::iterator i = mapProps.begin(); i != mapProps.end(); ++i) {
|
||||
if(i->first == "BGM") {
|
||||
@ -135,12 +157,18 @@ void Level::Update(float dt) {
|
||||
for(std::list<Layer*>::iterator i = _layers.begin(); i != _layers.end(); ++i) {
|
||||
(*i)->Update(dt);
|
||||
}
|
||||
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
|
||||
(*i)->Update(dt);
|
||||
}
|
||||
}
|
||||
|
||||
void Level::Draw(int xOffset, int yOffset) {
|
||||
for(std::list<Layer*>::iterator i = _layers.begin(); i != _layers.end(); ++i) {
|
||||
(*i)->Draw(xOffset, yOffset);
|
||||
}
|
||||
for(std::list<NPC*>::iterator i = _npcs.begin(); i != _npcs.end(); ++i) {
|
||||
(*i)->Render();
|
||||
}
|
||||
}
|
||||
|
||||
bool Level::CheckCollision(float x, float y, float w, float h) const {
|
||||
|
@ -6,6 +6,7 @@
|
||||
class Layer;
|
||||
class Tileset;
|
||||
class Music;
|
||||
class NPC;
|
||||
|
||||
class Level {
|
||||
public:
|
||||
@ -33,6 +34,7 @@ private:
|
||||
int _tileHeight;
|
||||
std::list<Layer*> _layers;
|
||||
std::list<Tileset*> _tilesets;
|
||||
std::list<NPC*> _npcs;
|
||||
Music* _bgm;
|
||||
bool* _collisions;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user