]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
chests, item dropping
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 29 Jun 2016 21:56:48 +0000 (17:56 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 29 Jun 2016 21:56:48 +0000 (17:56 -0400)
16 files changed:
Changelog
brice.dat
include/entities.hpp
include/inventory.hpp
include/texture.hpp
include/world.hpp
main.cpp
src/entities.cpp
src/inventory.cpp
src/mob.cpp
src/ui.cpp
src/world.cpp
xml/bobshouse.xml
xml/playerSpawnHill1.xml
xml/playerSpawnHill1_Building1.xml
xml/town.xml

index ee05b8539ed8dcfacc054e65c29cba2258e80b52..b530132c6dda6001ce4983e6dd9d7ccd8e9c5d28 100644 (file)
--- a/Changelog
+++ b/Changelog
@@ -1071,3 +1071,11 @@ Late June (6/16/2016 - 6/27/2016)
                - redid forest trees, mountains, houses
        - fixed major issue with entering structures
        - exploring more ideas for soundtracks
+
+6/29/2016:
+==========
+
+       - added chests
+       - added q to drop items, as objects
+       - chests snag dropped objects, right click to reclaim
+       - control setting is good, needs saving though
index 2033bae64b8c312af83dfe1243c6508df9c542aa..4dad7115c21edf220ed1e407b1d7f9f20b430ea0 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,7 +1,7 @@
 3
-canSprint
-1
-canJump
-0
 Slow
 0
+canJump
+0
+canSprint
+1
index 4abb3cbef3b1154acddfaf17bb91789868a32b4f..2d96a9fdd63c033e4e52af912e5e92d5827da943 100644 (file)
@@ -386,9 +386,8 @@ public:
 };
 
 class Object : public Entity{
-private:
-       std::string iname;
 public:
+       std::string iname;
        std::string pickupDialog;
        bool questObject = false;
 
index a85e537e93aed19937a480f0a835254f4af7632d..ca402b31024b3d2a73867fbccedfe9c4bf6a21e8 100644 (file)
@@ -219,13 +219,16 @@ public:
 /***********************************************************************************
  *                                             OLD STUFF THAT NEEDS TO GET UPDATED                                                *
  **********************************************************************************/
+
+using InventorySlot = std::pair<Item *, unsigned int>;
+
 class Inventory {
 private:
        unsigned int size; //how many slots our inventory has
        unsigned int sel; //what item is currently selected
        int os = 0;
 public:
-       std::vector<std::pair<Item*, uint>> Items;
+       std::vector<InventorySlot> Items;
 
        bool invOpen = false; //is the inventory open
        bool invOpening = false; //is the opening animation playing
@@ -253,6 +256,8 @@ public:
        void setSelectionDown();
 
        void draw(void);        // Draws a text list of items in this inventory (should only be called for the player for now)
+
+       const Item* getCurrentItem(void);
 };
 
 void initInventorySprites(void);
index c301af1a46041350df07eb82151144b61c80d085..7f22a790ade742c492006820c01628b3367f40fb 100644 (file)
@@ -46,6 +46,9 @@ public:
        TextureIterator(void) {
                position = std::begin(textures);
        }
+       ~TextureIterator(void) {
+               textures.clear();
+       }
        TextureIterator(const std::vector<std::string> &l) {
                for (const auto &s : l)
                        textures.emplace_back(Texture::loadTexture(s), s);
index a2de048baeed6b5bdb0e9c78444f3eb4a737f6da..9a892d8bb4a1773aa40c1dc268bcec3f49997130 100644 (file)
@@ -66,7 +66,7 @@ extern std::string currentXML;
 /**
  * Defines how many game ticks it takes to go from day to night or vice versa.
  */
-constexpr const unsigned int DAY_CYCLE = 12000;
+constexpr const unsigned int DAY_CYCLE = 10000;
 
 /**
  * Defines the velocity of player when moved by the keyboard
index fd8ed4d3a498d5044e44c9f083883bcf2dddca72..1bfce773df73ea1450550812c8dedc59bc21aab6 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -265,8 +265,8 @@ int main(int argc, char *argv[])
                for (const auto &xf : xmlFiles) {
                        if (xf[0] != '.') {
                                XMLDocument xmld;
-                               auto file = (xmlFolder + xf).c_str();
-                               xmld.LoadFile(file);
+                               auto file = xmlFolder + xf;
+                               xmld.LoadFile(file.c_str());
 
                                auto xmle = xmld.FirstChildElement("World");
 
@@ -286,7 +286,8 @@ int main(int argc, char *argv[])
                                        xmle->DeleteAttribute("dindex");
                                        xmle = xmle->NextSiblingElement();
                                }
-                               xmld.SaveFile(file, false);
+
+                               xmld.SaveFile(file.c_str(), false);
                        }
                }
 
@@ -328,6 +329,10 @@ int main(int argc, char *argv[])
        arena->setBackground(WorldBGType::Forest);
        arena->setBGM("assets/music/embark.wav");
 
+
+       player->inv->addItem("Wood Sword", 10);
+
+
        // the main loop, in all of its gloriousness..
        std::thread([&]{
                while (gameRunning) {
index 0c312e2c462208e43ebbcd901c66d657a4ef8bd0..f4c020c162a7d78001952470ded5a5700c277848 100644 (file)
@@ -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
index ede5eeb1e4938c0b6953bf6bb415897645946e3f..7e8c94ea07d701b2a5121b731507c2e87741fea7 100644 (file)
@@ -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;
+}
index 20273d6d6b190abd63130dcdf5cff88bfa60c737..99d6f345e94f44c21123ec2dcf62a07718f0f91e 100644 (file)
@@ -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)
index f3523f645af0e7aec10c7686517079b59381535a..18bae1b4e05f35cfec6780f6a71d0df2b1f1d7ec 100644 (file)
@@ -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;
index 7294fdaf0cf170895eb3281003229f6c1299b9d7..9c51ec8ba9761c06bf3d7cfc61779d0bc821bc1d 100644 (file)
@@ -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 = "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 = "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)
index ebf020bdad917a8d81fef9ab9fe12b3f8052c09d..2d6981366d25839c590451f970e9ed96bd0a9a4d 100644 (file)
@@ -3,5 +3,5 @@
     <style background="1" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
     <floor width="1600"/>
     <link outside="town.xml"/>
-    <npc name="Bob" hasDialog="false" spawnx="30"/>
+    <npc name="Bob" hasDialog="false" spawnx="30" health="1" x="-229.27991" y="0" dindex="9999"/>
 </IndoorWorld>
index 92e4c875c50206617c8bbfa727da8bd7b22e80d1..73fe104cb62821e66666936d9affa9f04e4dc8aa 100644 (file)
 <Dialog name="Guy">
     <text id="0" nextid="1">
                Hello there! My name is Ralph.
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       <gotox>300</gotox>
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <gotox>300</gotox>
     </text>
     <text id="1">
                ...
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       <gotox>1000</gotox>
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <gotox>1000</gotox>
         <set id="Slow" value="0"/>
         <set id="canSprint" value="1"/>
     </text>
@@ -33,5 +33,5 @@
     <text id="0" stop="true">
                Hey friend! It's dangerous out there, here take these!
                Wait, promise you'll stop by my stand in the local market!
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       <give id="Wood Sword" count="1"/>        <give id="Hunters Bow" count="1"/>        <give id="Crude Arrow" count="110"/>        <give id="Fried Chicken" count="1"/>        <give id="Mossy Torch" count="1"/></text>
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <give id="Wood Sword" count="1"/>        <give id="Hunters Bow" count="1"/>        <give id="Crude Arrow" count="110"/>        <give id="Fried Chicken" count="1"/>        <give id="Mossy Torch" count="1"/></text>
 </Dialog>
index 74eec7619cfefe56eb574ab68558c4fdfb1884f5..4fd30cb174890701a9d13196e36fcfcccfdff57a 100644 (file)
 <Dialog name="Bob">
     <text id="0" nextid="1" pause="true">
        Hey. Have a Dank MayMay :)
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <give id="Dank MayMay" count="1"/></text>
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       <give id="Dank MayMay" count="1"/></text>
     <text id="1" nextid="2">
        What? You want another Dank MayMay?
     </text>
     <text id="2" nextid="3" pause="true">
                K.
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           <give id="Dank MayMay" count="1"/></text>
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   <give id="Dank MayMay" count="1"/></text>
     <text id="3" nextid="4">
                Well... I'm out of Dank MayMays.
        </text>
     <text id="4">
                Have a sword though.
-                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       <give id="Wood Sword" count="1"/></text>
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <give id="Wood Sword" count="1"/></text>
 </Dialog>
index 5ee83976d48dd333e6434fc3e62e4357dc6138ba..b9da09c711a17e61e4fb05f800717c11c3d69e24 100644 (file)
@@ -4,8 +4,8 @@
     <generation type="Random" width="1600"/>
     <time>6000</time>
     <spawnx>-300</spawnx>
-    <npc name="Sanc" hasDialog="true" health="1" x="414.76144" y="62.599087" dindex="9999"/>
-    <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="356.11185" y="60.999081" dindex="0"/>
+    <npc name="Sanc" hasDialog="true" health="1" x="464.45755" y="65.399185" dindex="0"/>
+    <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="-772.5" y="59.999001" dindex="0"/>
     <structure type="1" spawnx="300" alive="1"/>
     <structure inside="bobshouse.xml" type="1" spawnx="10" alive="1"/>
     <chest alive="1"/>
@@ -13,6 +13,7 @@
 
 <Dialog name="Bob">
     <text id="0" nextid="1" pause="true">
+        <give id="Dank MayMay" count="10"/>
         <content alive="1">
                        Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
                </content>