diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2017-10-20 10:30:53 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2017-10-20 10:30:53 -0400 |
commit | dff621732099934ba5aba09c6b5c3df87b9858b5 (patch) | |
tree | a4121d241a322c0a8c679ce6ba03f33bc9bb5622 /src | |
parent | 1a4780bad1cc40b43ebe6d93baba0f89572194d4 (diff) |
bow/arrow updates, food
Diffstat (limited to 'src')
-rw-r--r-- | src/attack.cpp | 3 | ||||
-rw-r--r-- | src/inventory.cpp | 38 | ||||
-rw-r--r-- | src/player.cpp | 11 | ||||
-rw-r--r-- | src/ui_menu.cpp | 10 |
4 files changed, 43 insertions, 19 deletions
diff --git a/src/attack.cpp b/src/attack.cpp index 16c7f8a..8c5d44a 100644 --- a/src/attack.cpp +++ b/src/attack.cpp @@ -96,7 +96,8 @@ void AttackSystem::update(entityx::EntityManager& en, entityx::EventManager& ev, //point.y -= size.y / 2; // center range height vec2 point = a.pos + a.attack.offset; - vec2 size; + vec2 size (0, a.attack.range.y); + point.y -= size.y / 2; a.attack.script("hit", {LuaVariable("xrange", size.x)}); en.each<Position, Solid, Health>( diff --git a/src/inventory.cpp b/src/inventory.cpp index 0ed5dc7..947c7fc 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -71,6 +71,8 @@ void InventorySystem::loadItems(void) { item.sound = nullptr; item.cooldown = 250; itm->QueryIntAttribute("cooldown", &item.cooldown); + auto drawOffset = itm->StrAttribute("drawOffset"); + item.drawOffset = drawOffset; auto atk = itm->FirstChildElement("attack"); if (atk != nullptr) { @@ -197,6 +199,7 @@ void InventorySystem::render(void) auto pos = PlayerSystem::getPosition(); vec2 sta (pos.x, pos.y); + sta += i.item->drawOffset; vec2 end (sta + (i.item->sprite.getDim() * game::HLINE)); GLfloat coords[] = { sta.x, sta.y, -8, 0, 1, @@ -219,17 +222,32 @@ void InventorySystem::render(void) bool InventorySystem::receive(const MouseClickEvent &mce) { if (mce.button == SDL_BUTTON_RIGHT) { - game::entities.each<ItemDrop>([&](entityx::Entity e, ItemDrop& id) { - auto& posComp = *e.component<Position>(); - auto& dimComp = *e.component<Solid>(); - vec2 sta (posComp.x, posComp.y); - vec2 end (sta.x + dimComp.width, sta.y + dimComp.height); - - if (mce.position > sta && mce.position < end) { - add(id.item.item->name, id.item.count); - e.destroy(); + if ((mce.position > hotStart && mce.position < hotEnd) || + (fullInventory && mce.position > fullStart && mce.position < fullEnd)) { + int end = fullInventory ? items.size() : hotbarSize; + for (int i = 0; i < end; i++) { + if (!isGoodEntry(items[i])) + continue; + + if (mce.position > items[i].loc && mce.position < items[i].loc + entrySize) { + if (items[i].item->type == "Food") + game::events.emit<UseItemEvent>(mce.position, items[i].item); + break; + } } - }); + } else { + game::entities.each<ItemDrop>([&](entityx::Entity e, ItemDrop& id) { + auto& posComp = *e.component<Position>(); + auto& dimComp = *e.component<Solid>(); + vec2 sta (posComp.x, posComp.y); + vec2 end (sta.x + dimComp.width, sta.y + dimComp.height); + + if (mce.position > sta && mce.position < end) { + add(id.item.item->name, id.item.count); + e.destroy(); + } + }); + } } else if (mce.button == SDL_BUTTON_LEFT) { if ((mce.position > hotStart && mce.position < hotEnd) || (fullInventory && mce.position > fullStart && mce.position < fullEnd)) { diff --git a/src/player.cpp b/src/player.cpp index ef1752f..db34347 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -232,7 +232,8 @@ bool PlayerSystem::receive(const UseItemEvent& uie) if (InventorySystem::take("Arrow", 1)) { auto e = game::entities.create(); auto pos = getPosition(); - e.assign<Position>(pos.x, pos.y + 10); + auto dim = player.component<Solid>(); + e.assign<Position>(pos.x + dim->width / 2, pos.y + dim->height / 2); auto angle = std::atan2(uie.curs.y - pos.y, uie.curs.x - pos.x); e.assign<Direction>(0.25f * std::cos(angle), 0.25f * std::sin(angle)); @@ -244,12 +245,16 @@ bool PlayerSystem::receive(const UseItemEvent& uie) auto frame = SpriteData(tex->sprite); frame.veltate = true; sprite->addSpriteSegment(frame, 0); - auto dim = HLINES(sprite->getSpriteSize()); - e.assign<Solid>(dim.x, dim.y); + auto adim = sprite->getSpriteSize(); + e.assign<Solid>(adim.x, adim.y); + uie.attack->range.y = player.component<Solid>()->height; e.assign<Hit>(uie.attack); if (uie.attack->effect.size() > 0) e.component<Hit>()->effect = uie.attack->effect; } + } else if (uie.item->type == "Food") { + player.component<Health>()->health = player.component<Health>()->maxHealth; + InventorySystem::take(uie.item->name, 1); } cool.store(false); diff --git a/src/ui_menu.cpp b/src/ui_menu.cpp index 052030a..f0b2eeb 100644 --- a/src/ui_menu.cpp +++ b/src/ui_menu.cpp @@ -179,16 +179,16 @@ namespace ui { Color black (0, 0, 0); // Create the main pause menu pauseMenu.items.push_back(ui::menu::createParentButton( - vec2(-128, 100), obSize, black, "Resume")); + vec2(-128, 150), obSize, black, "Resume")); pauseMenu.items.push_back(ui::menu::createChildButton( - vec2(-128, 0), obSize, black, "Options", &optionsMenu)); + vec2(-128, 50), obSize, black, "Options", &optionsMenu)); pauseMenu.items.push_back(ui::menu::createChildButton( - vec2(-128, -100), obSize, black, "Controls", &controlsMenu)); + vec2(-128, -50), obSize, black, "Controls", &controlsMenu)); pauseMenu.items.push_back(ui::menu::createButton( - vec2(-128, -200), obSize, black, "Save and Quit", + vec2(-128, -150), obSize, black, "Save and Quit", []() { game::config::update(); // TODO necessary? game::config::save(); @@ -196,7 +196,7 @@ namespace ui { } )); pauseMenu.items.push_back(ui::menu::createButton( - vec2(-128, -300), obSize, black, "Segfault", + vec2(-128, -250), obSize, black, "Segfault", []() { ++*((int *)0); } )); // Create the options (sound) menu |