diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2016-06-29 17:56:48 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2016-06-29 17:56:48 -0400 |
commit | 3766c45c62eeca442e9ab700c09c547f08615b62 (patch) | |
tree | 37e2c5c2c28f7a0c79eb39daa6276e018595be18 /src | |
parent | df12451f837854c816bed32ae0d962fba9601959 (diff) |
chests, item dropping
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 3 | ||||
-rw-r--r-- | src/inventory.cpp | 8 | ||||
-rw-r--r-- | src/mob.cpp | 17 | ||||
-rw-r--r-- | src/ui.cpp | 7 | ||||
-rw-r--r-- | src/world.cpp | 14 |
5 files changed, 41 insertions, 8 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index 0c312e2..f4c020c 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -188,6 +188,7 @@ Player::Player() : Entity() Player::~Player() { delete inv; + delete &tex; } void Player::createFromXML(XMLElement *e, World *w=nullptr) @@ -716,7 +717,7 @@ COMMONAIFUNC: // handle give tags if ((oxml = exml->FirstChildElement("give"))) { do player->inv->addItem(oxml->Attribute("id"), oxml->UnsignedAttribute("count")); - while ((oxml = oxml->NextSiblingElement())); + while ((oxml = oxml->NextSiblingElement("give"))); } // handle take tags diff --git a/src/inventory.cpp b/src/inventory.cpp index ede5eeb..7e8c94e 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -727,3 +727,11 @@ bool Inventory::detectCollision(vec2 one, vec2 two) { (void)two; return false; } + +const Item* Inventory::getCurrentItem(void) +{ + if (Items.size() > 0) + return Items[sel].first; + else + return nullptr; +} diff --git a/src/mob.cpp b/src/mob.cpp index 20273d6..99d6f34 100644 --- a/src/mob.cpp +++ b/src/mob.cpp @@ -432,11 +432,26 @@ Chest::Chest(void) : Mob() width = HLINES(10); height = HLINES(5); tex = TextureIterator({"assets/chest.png"}); + inv = new Inventory(1); } void Chest::act(void) { - //die(); + if (isInside(ui::mouse) && player->isNear(this)) { + if ((SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)) && !ui::dialogBoxExists) + for (auto &i : inv->Items) { + player->inv->addItem(i.first->name, i.second); + inv->takeItem(i.first->name, i.second); + } + } + + for (auto &e : currentWorld->entity) { + if (e->type == OBJECTT && e->isNear(this)) { + auto o = dynamic_cast<Object *>(e); + inv->addItem(o->iname, 1); + e->health = 0; + } + } } void Chest::onHit(unsigned int _health) @@ -1533,6 +1533,13 @@ EXIT: action::disable(); heyOhLetsGo = 0; + } else if (SDL_KEY == SDLK_q) { + auto item = player->inv->getCurrentItem(); + if (item != nullptr) { + if (player->inv->takeItem(item->name, 1) == 0) + currentWorld->addObject(item->name, "o shit waddup", + player->loc.x + player->width / 2, player->loc.y + player->height / 2); + } } else switch (SDL_KEY) { case SDLK_F3: debug ^= true; diff --git a/src/world.cpp b/src/world.cpp index 7294fda..9c51ec8 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -780,26 +780,26 @@ singleDetect(Entity *e) if (entity[i] == e) { switch (e->type) { case STRUCTURET: - killed = "structure"; + killed = " structure"; build.erase(std::find(std::begin(build), std::end(build), e)); break; case NPCT: - killed = "NPC"; + killed = "n NPC"; npc.erase(std::find(std::begin(npc), std::end(npc), e)); break; case MOBT: - killed = "mob"; + killed = " mob"; mob.erase(std::find(std::begin(mob), std::end(mob), e)); break; case OBJECTT: - killed = "object"; + killed = "n object"; object.erase(std::find(std::begin(object), std::end(object), *Objectp(e))); break; default: break; } - std::cout << "Killed a " << killed << "...\n"; + std::cout << "Killed a" << killed << "...\n"; entity.erase(entity.begin() + i); return; } @@ -1823,7 +1823,9 @@ loadWorldFromXMLNoSave(std::string path) { return nullptr; _currentXML = xmlFolder + path; - _currentXMLRaw = readFile(_currentXML.c_str()); + const char *worthless = readFile(_currentXML.c_str()); + _currentXMLRaw = worthless; + delete[] worthless; // create a temporary XMLDocument if this isn't the main world if (!loadedLeft && !loadedRight) |