]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
skirl; angry
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 10 Feb 2017 01:26:32 +0000 (20:26 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 10 Feb 2017 01:26:32 +0000 (20:26 -0500)
Makefile
include/components.hpp
src/components.cpp
src/inventory.cpp
src/particle.cpp
src/quest.cpp
src/world.cpp
xml/!town.xml
xml/entities.xml

index 996c5559995dfb1134bf6a1af2e8707fbe1c881a..dd821964907396d71375ed01cf8680bb8e236efe 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -25,10 +25,6 @@ EXEC = main
 
 all: SPECIAL:=-ggdb game
 
-release: SPECIAL = -static
-release: LIBS += -lm -ldinput8 -ldxguid -ldxerr8 -luser32 -lgdi32 -lwinmm -limm32 -lole32 -loleaut32 -lshell32 -lversion -luuid
-release: game
-
 game: $(EXEC)
 
 clean:
index 14cff813d1129d7c3157589cda6fb59e931419b4..ebc256dd3fa493a3b78f0450c7d960d10f3d118d 100644 (file)
@@ -408,6 +408,16 @@ struct Wander {
        int countdown;
 };
 
+/**
+ * Causes the entity to get mad at the player, charge and fight.
+ */
+struct Aggro {
+       Aggro(const std::string& a)
+               : arena(a) {}
+
+       std::string arena;
+};
+
 /**
  * SYSTEMS
  */
index 7cb533c9e9f8af0a6090d0ca1f2c495092bd622b..7506d40e88f8ac45c7228046c87e77575667ace4 100644 (file)
@@ -6,11 +6,13 @@
 #include <render.hpp>
 #include <ui.hpp>
 #include <engine.hpp>
+#include <error.hpp>
 #include <world.hpp>
 #include <brice.hpp>
 #include <quest.hpp>
 #include <glm.hpp>
 #include <fileio.hpp>
+#include <player.hpp>
 
 #include <atomic>
 
@@ -45,7 +47,18 @@ void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &e
 
                        // make the entity wander
                        // TODO initialX and range?
-                       if (entity.has_component<Wander>()) {
+                       if (entity.has_component<Aggro>()) {
+                               auto ppos = game::engine.getSystem<PlayerSystem>()->getPosition();
+                               if (ppos.x > position.x && ppos.x < position.x + entity.component<Solid>()->width) {
+                                       ui::toggleWhiteFast();
+                                       ui::waitForCover(); // TODO thread safe call to load world?
+                                       //game::engine.getSystem<WorldSystem>()->load(entity.component<Aggro>()->arena);
+                                       ui::toggleWhiteFast();
+                                       entity.destroy();
+                               } else {
+                                       direction.x = (ppos.x > position.x) ? .05 : -.05;
+                               }
+                       } else if (entity.has_component<Wander>()) {
                                auto& countdown = entity.component<Wander>()->countdown;
 
                                if (countdown > 0) {
@@ -212,6 +225,15 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                                        game::briceUpdate();
                                                }
 
+                                               auto ixml = exml->FirstChildElement("give");
+                                               if (ixml != nullptr) {
+                                                       do {
+                                                               game::engine.getSystem<InventorySystem>()->add(
+                                                                       ixml->StrAttribute("name"), ixml->IntAttribute("count"));
+                                                               ixml = ixml->NextSiblingElement();
+                                                       } while (ixml != nullptr);
+                                               }
+
                                                auto qxml = exml->FirstChildElement("quest");
                                                if (qxml != nullptr) {
                                                        const char *qname;
index fd844f5db03272971bc3e28242a31d142ea3e578..f1332f2a93ab1bafe1bcc896d0f24a1946cb92f5 100644 (file)
@@ -22,7 +22,7 @@ static bool fullInventory = false;
 
 constexpr int          entrySize = 70;
 constexpr int          hotbarSize = 4;
-constexpr float        inventoryZ = -6.0f;
+constexpr float        inventoryZ = -5.0f;
 constexpr unsigned int rowSize = 8;
 
 static int movingItem = -1;
@@ -100,7 +100,7 @@ void InventorySystem::render(void)
                glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1);
 
                // draw the item
-               if (i.item != nullptr) {
+               if (i.item != nullptr && i.count > 0) {
                        i.item->sprite.use();
                        static const GLfloat tex[12] = {0,1,1,1,1,0,1,0,0,0,0,1};
                        glVertexAttribPointer(Render::textShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
@@ -115,7 +115,7 @@ void InventorySystem::render(void)
                        if (n == movingItem)
                                glUniform4f(Render::textShader.uniform[WU_tex_color], .8, .8, 1, .8);
                        glDrawArrays(GL_TRIANGLES, 0, 6);
-                       ui::setFontZ(-7.2); // TODO fix z's
+                       ui::setFontZ(inventoryZ - 0.3); // TODO fix z's
                        ui::putText(sta.x, sta.y, std::to_string(i.count).c_str());
                        ui::setFontZ(-6);
                        glUniform4f(Render::textShader.uniform[WU_tex_color], 1, 1, 1, 1);
@@ -144,6 +144,9 @@ void InventorySystem::receive(const MouseClickEvent &mce)
                int end = fullInventory ? items.size() : hotbarSize;
                movingItem = -1;
                for (int i = 0; i < end; i++) {
+                       if (items[i].item == nullptr || items[i].count == 0)
+                               continue;
+
                        if (mce.position > items[i].loc && mce.position < items[i].loc + entrySize) {
                                movingItem = i;
                                break;
index 6eeec338ccc01a5cae80c53c69a345ccd6ffdaa5..006bc45d1836cb259c6add71f75bd8346fe208c2 100644 (file)
@@ -36,7 +36,7 @@ void ParticleSystem::render(void)
                // generate VBO
                glGenBuffers(1, &particleVBO);
                glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
-               glBufferData(GL_ARRAY_BUFFER, maximum * entrySize, nullptr,     GL_STREAM_DRAW);
+               glBufferData(GL_ARRAY_BUFFER, maximum * entrySize, nullptr,     GL_DYNAMIC_DRAW);
        }
 
        // clear dead particles
@@ -46,7 +46,7 @@ void ParticleSystem::render(void)
        // copy data into VBO
        glBindBuffer(GL_ARRAY_BUFFER, particleVBO);
 
-       for (unsigned int i = 0, offset = 0; i < parts.size() - 1; i++, offset += entrySize) {
+       for (unsigned int i = 0, offset = 0; i < parts.size(); i++, offset += entrySize) {
                const auto& p = parts[i];
                static const auto& hl = game::HLINE;
                GLfloat coords[30] = {
index 8107eb65d857460fd94fb830f4ee3ddc529eae80..920ac845f2322ab365e2ec6d357f89159bcc101c 100644 (file)
@@ -2,7 +2,20 @@
 
 #include <algorithm>
 
-extern std::vector<std::string> StringTokenizer(const std::string& str, char delim);
+std::vector<std::string> StringTokenizer(const std::string& str, char delim);
+
+std::vector<std::string> split(std::string s, const std::string& delim)
+{
+       std::vector<std::string> res;
+
+       while (!s.empty()) {
+               auto pos = s.find(delim);
+               res.emplace_back(s.substr(0, pos));
+               s = s.substr(pos + 1);
+       }
+
+       return res;
+}
 
 void QuestSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
 {
index 4f2f99c4771182ed54312eb4b08f94d7deb277ce..8db9344972fcbe5a71e741c32f9d00c41205bcd3 100644 (file)
@@ -203,20 +203,25 @@ void WorldSystem::load(const std::string& file)
                UserError("XML Error: Failed to parse file (not your fault though..?)");
 
        // include headers
+       std::vector<std::string> toAdd;
        auto ixml = xmlDoc.FirstChildElement("include");
        while (ixml != nullptr) {
                auto file = ixml->Attribute("file");
 
                if (file != nullptr) {
                        DEBUG_printf("Including file: %s\n", file);
-                       xmlRaw.append(readFile(xmlFolder + file));
+                       toAdd.emplace_back(xmlFolder + file);
+                       //xmlRaw.append(readFile(xmlFolder + file));
                } else {
                        UserError("XML Error: <include> tag file not given");
                }
 
-               break;//ixml = ixml->NextSiblingElement();
+               ixml = ixml->NextSiblingElement("include");
        }
 
+       for (const auto& f : toAdd)
+               xmlRaw.append(readFile(f)); 
+
        if (xmlDoc.Parse(xmlRaw.data()) != XML_NO_ERROR)
                UserError("XML Error:");
 
@@ -385,6 +390,8 @@ void WorldSystem::load(const std::string& file)
                                                entity.assign<Wander>();
                                        } else if (tname == "Hop" ) {
                                                entity.assign<Hop>();
+                                       } else if (tname == "Aggro" ) {
+                                               entity.assign<Aggro>(abcd->Attribute("arena"));
                                        } else if (tname == "Animation") {
                                                auto entan = entity.assign<Animate>();
                                                auto animx = abcd->FirstChildElement();
index 47ddf273292849f1f6f6ba89ee363007544c87fd..eb5392175f1109b1f60bac4cd7ee908fdfca712a 100644 (file)
     <npc name="Bob" hasDialog="true" position="50.0,100.0"/>
     <structure type="1" position="300.0,100.0"/>
     <structure inside="bobshouse.xml" type="1" position="10.0,100.0"/>
+       <skirl />
 </World>
 
 <Dialog name="Bob">
     <text id="0" nextid="1" pause="true">
-        <give id="Dank MayMay" count="10"/>
+        <give name="Dank MayMay" count="10"/>
         <content>
                        Hey there! The name's Bob. Good to see you've finally woken up from your nap by the cliff there... lol
                </content>
     </text>
     <text id="1" pause="true">
-        <quest assign="Check out m&apos;swag, man!" desc="Go inside Bob&apos;s house and check out the stuff he has."/>
+        <quest assign="Check out m&apos;swag, man!" desc="Go inside Bob&apos;s house and check out the stuff he has.">
+                       Debug, 5
+               </quest>
         <content>
                        Looks like you've got yourself pretty empty handed... you know, I have a simple solution for that. Come on inside, I have somethin' to show you.
                </content>
index 04faac5e7c4eb2a3926e4f0854e3b1db3140dc84..7195b518954f5cf9d50e9acf05e7ddbce0db2efc 100644 (file)
        <Wander />
 </npc>
 
+<skirl>
+       <Position value="300.0,100.0" />
+       <Visible value="0.2" />
+       <Sprite>
+               <frame>
+                       <src limb="0" offset="0,0" size="48,24" drawOffset="0,0">assets/skirl.png</src>
+               </frame>
+       </Sprite>
+       <Direction />
+       <Solid />
+       <Physics />
+       <Name value="SKIRL" />
+       <Wander />
+       <Aggro arena="bobshouse.xml" />
+</skirl>
+
 <structure>
        <Position value="0.0,100.0" />
        <Visible value="0.25" />