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 | |
parent | 1a4780bad1cc40b43ebe6d93baba0f89572194d4 (diff) |
bow/arrow updates, food
-rw-r--r-- | config/items.xml | 10 | ||||
-rw-r--r-- | include/inventory.hpp | 1 | ||||
-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 | ||||
-rw-r--r-- | xml/!town.xml | 6 | ||||
-rw-r--r-- | xml/entities.xml | 4 | ||||
-rw-r--r-- | xml/snow.xml | 1 |
9 files changed, 59 insertions, 25 deletions
diff --git a/config/items.xml b/config/items.xml index 574ddda..a70996a 100644 --- a/config/items.xml +++ b/config/items.xml @@ -10,15 +10,15 @@ <item name="Dank MayMay" type="Tool" value="10" maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" /> <item name="Your Bag" type="Equip" value="32" maxStackSize="1" width="5" height="5" sprite="assets/items/ITEM_TEST.png" /> <item name="Flashlight" type="Tool" value="1" maxStackSize="1" width="4" height="8" sprite="assets/items/flashlight_off.png" /> -<item name="Fried Chicken" type="Cooked Food" value="10" maxStackSize="6" sprite="assets/items/FOOD_CHICKEN_FRIED.png" /> +<item name="Fried Chicken" type="Food" value="10" maxStackSize="6" sprite="assets/items/FOOD_CHICKEN_FRIED.png" /> <!--###########--> <!-- NEW ITEMS --> <!--##########--> <!-- WEAPONS --> -<item name="Wood Sword" type="Sword" damage="3" maxStackSize="1" sound="assets/sounds/longSwing.wav" sprite="assets/items/SWORD_WOOD.png" cooldown="250"> - <attack range="6, 2" power="1" effect="assets/effects/starAttack.gif"> +<item name="Wood Sword" type="Sword" maxStackSize="1" sound="assets/sounds/longSwing.wav" sprite="assets/items/SWORD_WOOD.png" cooldown="250"> + <attack effect="assets/effects/starAttack.gif"> i = 1 effect = function() @@ -27,7 +27,7 @@ end hit = function() - if (i < 30) then + if (i < 80) then xrange = i i = i + 1 else @@ -36,7 +36,7 @@ end </attack> </item> -<item name="Hunters Bow" type="Bow" damage="2" maxStackSize="1" sprite="assets/items/bow.png" cooldown="600"> +<item name="Hunters Bow" type="Bow" drawOffset="5,16" maxStackSize="1" sprite="assets/items/bow.png" cooldown="600"> <attack effect="assets/effects/starAttack.gif"> effect = function() flash(255, 0, 255) diff --git a/include/inventory.hpp b/include/inventory.hpp index f8581cc..273241a 100644 --- a/include/inventory.hpp +++ b/include/inventory.hpp @@ -33,6 +33,7 @@ struct Item { TextureIterator effect; /**< Animation played on item use */ Mix_Chunk* sound; /**< The sound to play on item use */ int cooldown; + vec2 drawOffset; Item(void) : value(0), stackSize(1), cooldown(0) {} 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 diff --git a/xml/!town.xml b/xml/!town.xml index a038bee..29673b0 100644 --- a/xml/!town.xml +++ b/xml/!town.xml @@ -52,9 +52,13 @@ </Dialog> <Dialog name="Sanc"> - <text id="0" nexit="0" pause="true"> + <text id="0" nextid="1" pause="true"> <set id="Slow" value="0"/> <set id="canSprint" value="1"/> <set id="canJump" value="1"/> </text> + <text id="1" nextid="1"> + <give name="Arrow" count="20" /> + <content>Have some more, bud.</content> + </text> </Dialog> diff --git a/xml/entities.xml b/xml/entities.xml index 921e837..96c8d79 100644 --- a/xml/entities.xml +++ b/xml/entities.xml @@ -133,7 +133,11 @@ <Direction /> <Solid /> <Physics /> + <Health value="25" /> <Name value="birb" /> + <Drop> + <item name="Fried Chicken" min="1" max="3" /> + </Drop> <Wander> countdown = 0 onetime = 0 diff --git a/xml/snow.xml b/xml/snow.xml index 8a62277..3c81f65 100644 --- a/xml/snow.xml +++ b/xml/snow.xml @@ -22,5 +22,6 @@ <firefly /> <firefly /> <firefly /> + <birb /> </World> |