]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world saving / new game script stuff
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 15 Jun 2016 11:40:52 +0000 (07:40 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 15 Jun 2016 11:40:52 +0000 (07:40 -0400)
12 files changed:
Changelog
assets/music/africa.mp3 [new file with mode: 0644]
brice.dat
include/entities.hpp
include/world.hpp
main.cpp
src/entities.cpp
src/world.cpp
xml/000.xml
xml/001.xml [new file with mode: 0644]
xml/playerSpawnHill1.xml
xml/playerSpawnHill1_Building1.xml

index 9cbe9954f1d3c68abd166dd39f16b995595b00e1..0f6c7484388d6879fbab4a3a338c4857e5654796 100644 (file)
--- a/Changelog
+++ b/Changelog
        - game is overall better
        - following lights, good lights
        - good
+
+6/13/2016:
+==========
+
+       - more actual finally story work
+       - laughed at Goals.txt
+       - worked on better inventory / general ui
+
+       ~ more than 10800 lines of code (just counting .hpp's and .cpp's)
diff --git a/assets/music/africa.mp3 b/assets/music/africa.mp3
new file mode 100644 (file)
index 0000000..c6073d5
Binary files /dev/null and b/assets/music/africa.mp3 differ
index 3b090ad887b4d2aa51cf2d99adc0eeaf055a2798..ee48d24d65e33bbcde48fb7aa0a01dd6e0ce641b 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,7 +1,7 @@
 3
-canSprint
+Slow
 0
 canJump
 0
-Slow
-1
+canSprint
+0
index 605cc771862cf8d8a85764921b9826423dd00d47..7e68be32df9bc5b57d37db2ed06f83265404fa8d 100644 (file)
@@ -160,7 +160,7 @@ public:
        bool near;
 
        // when true, the entity can move
-       bool canMove;
+       int canMove;
 
        // tells direction entity is facing
        bool right, left;
index e240973f294f53f8c146d2430a7b519a11dd3f02..cea79c10491ce37146a5532cc21f02ecee079168 100644 (file)
@@ -397,8 +397,8 @@ public:
         */
        std::string getSTextureLocation(unsigned int index) const;
 
-       // saves the world's data to an XML file
-       void save(void);
+       // saves the world's data to an XML file, either the one provided or the current path
+       void save(const std::string& s="");
 
        // plays/pauses the world's music, according to if a new world is being entered
        void bgmPlay(World *prev) const;
index 9c0ba2fee093af7599a8d375b0d1ce79ea80fbc2..52841c68fb09e58b236ae20f2e2b83c41e79b863 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -33,7 +33,7 @@ constexpr const char *GAME_NAME = "Independent Study v0.8 alpha - NOW WITH decen
 SDL_Window *window = NULL;
 
 // main loop runs based on this variable's value
-bool gameRunning = false;
+bool gameRunning = true;
 
 // world objects for the current world and the two that are adjacent
 World *currentWorld        = NULL,
@@ -325,7 +325,6 @@ int main(int argc, char *argv[])
        arena->setBGM("assets/music/embark.wav");
 
        // the main loop, in all of its gloriousness..
-       gameRunning = true;
        std::thread([&]{
                while (gameRunning) {
                        mainLoop();
index 9f9a47cb756c204e21592d8649532517b6290d23..90e03ebb841e16ab7d9157f3023bd7509e3a953f 100644 (file)
@@ -7,6 +7,7 @@
 #include <ui.hpp>
 #include <world.hpp>
 #include <gametime.hpp>
+#include <brice.hpp>
 
 extern std::istream *names;
 
@@ -638,6 +639,8 @@ void NPC::interact() { //have the npc's interact back to the player
                std::string nname;
                unsigned int idx;
                bool stop;
+               float tgt = 0.12345678f;
+               bool pmove = true, advance = false;
 
                loc.y += 5;
 
@@ -707,8 +710,20 @@ COMMONAIFUNC:
                        }
 
                        // handle movement directs
-                       if ((oxml = exml->FirstChildElement("gotox")))
-                               moveTo(std::stoi(oxml->GetText()));
+                       if ((oxml = exml->FirstChildElement("gotox"))) {
+                               moveTo((tgt = std::stoi(oxml->GetText())));
+                               if (oxml->QueryBoolAttribute("playerMove", &pmove) != XML_NO_ERROR)
+                                       pmove = true;
+                               if (oxml->QueryBoolAttribute("advance", &advance) != XML_NO_ERROR)
+                                       advance = false;
+                       }
+
+                       // handle attribute setting
+                       if ((oxml = exml->FirstChildElement("set"))) {
+                               do game::setValue(oxml->StrAttribute("id"), oxml->StrAttribute("value"));
+                               while ((oxml = oxml->NextSiblingElement()));
+                               game::briceUpdate();
+                       }
 
                        // asdlfkj
                        if (exml->GetText() == nullptr)
@@ -760,6 +775,20 @@ OTHERSTUFF:
                                }
                        }
 
+                       if (tgt != 0.12345678f) {
+                               stop = canMove;
+                               canMove = true;
+                               while (targetx != 0.9112001f) {
+                                       if (!pmove)
+                                               player->speed = 0;
+                               }
+                               if (!pmove) {
+                                       pmove = true;
+                                       player->speed = 1;
+                               }
+                               canMove = stop;
+                       }
+
                        // handle potential following dialogs
                        if ((idx = exml->UnsignedAttribute("nextid"))) {
                                dialogIndex = idx;
@@ -781,6 +810,10 @@ OTHERSTUFF:
                                }
                        }
 
+                       // advance if desired
+                       if (advance)
+                               goto COMMONAIFUNC;
+
                        // stop talking
                        else {
                                // error text?
index 2eebc4a499fff2941a2eecae399bcdf3375c9e2b..450d9567853c3a1908d124c44af05c110aa692d9 100644 (file)
@@ -797,7 +797,7 @@ void World::draw(Player *p)
         pc += 30;
                if (pc > pss) {
                        // TODO resize the vector or something better than breaking
-                       std::cout << "Whoops:" << pc << "," << partVec.size() << std::endl;
+                       //std::cout << "Whoops:" << pc << "," << partVec.size() << std::endl;
                        break;
                }
                particles[i].draw(pIndex);
@@ -1150,12 +1150,11 @@ getStructurePos(int index)
 /**
  * Saves world data to a file.
  */
-void World::save(void)
+void World::save(const std::string& s)
 {
        for (const auto &e : entity)
                e->saveToXML();
-
-       currentXMLDoc.SaveFile(currentXML.c_str(), false);
+       currentXMLDoc.SaveFile((xmlFolder + (s.empty() ? currentXML : s)).c_str(), false);
 }
 
 /**
@@ -1285,7 +1284,6 @@ std::string World::getToRight(void) const
 WorldSwitchInfo World::goWorldLeft(Player *p)
 {
        World *tmp;
-
     // check if player is at world edge
        if (!toLeft.empty() && p->loc.x < worldStart + HLINES(15)) {
         // load world (`toLeft` conditional confirms existance)
@@ -1305,7 +1303,6 @@ WorldSwitchInfo World::goWorldLeft(Player *p)
 WorldSwitchInfo World::goWorldRight(Player *p)
 {
        World *tmp;
-
        if (!toRight.empty() && p->loc.x + p->width > -worldStart - HLINES(15)) {
         tmp = loadWorldFromPtr(currentWorldToRight);
         return std::make_pair(tmp, vec2 {tmp->worldStart + (float)HLINES(15.0), GROUND_HEIGHT_MINIMUM} );
@@ -1851,24 +1848,28 @@ static bool loadedRight = false;
 
 World *loadWorldFromXML(std::string path) {
        if (!currentXML.empty())
-               currentWorld->save();
+               currentWorld->save(path);
 
        return loadWorldFromXMLNoSave(path);
 }
 
 World *loadWorldFromPtr(World *ptr)
 {
-    World *tmp = ptr;
-
-    loadedLeft = true;
-    currentWorldToLeft = loadWorldFromXML(tmp->getToLeft());
-    loadedLeft = false;
-
-    loadedRight = true;
-    currentWorldToRight = loadWorldFromXML(tmp->getToRight());
-    loadedRight = false;
+       currentWorld->save(); // save the current world to the current xml path
+       
+       if (ptr->getToLeft() == currentXML) {
+               currentWorldToLeft = currentWorld;
+               loadedRight = true;
+               currentWorldToRight = loadWorldFromXMLNoSave(ptr->getToRight());
+               loadedRight = false;
+       } else if (ptr->getToRight() == currentXML) {
+               currentWorldToRight = currentWorld;
+               loadedLeft = true;
+               currentWorldToLeft = loadWorldFromXMLNoSave(ptr->getToLeft());
+               loadedLeft = false;
+       }
 
-    return tmp;
+    return ptr;
 }
 
 /**
@@ -2009,7 +2010,7 @@ loadWorldFromXMLNoSave(std::string path) {
                }
 
                // set spawn x for player
-               else if (name == "spawnx") {
+               else if (name == "spawnx" && !(loadedLeft | loadedRight)) {
                        player->loc.x = std::stoi(wxml->GetText());
                }
 
@@ -2044,7 +2045,7 @@ loadWorldFromXMLNoSave(std::string path) {
                }
                
                // time setting
-               else if (name == "time") {
+               else if (name == "time" && !(loadedLeft | loadedRight)) {
             game::time::setTickCount(std::stoi(wxml->GetText()));
         }
                
index 9996cec1623cab9150df0ac098b4733ed45d3569..bf0af6c48b1ac3042868ef7dffbac10aa22f8ef2 100644 (file)
@@ -1,20 +1,25 @@
 <?xml version="1.0"?>
 <World>
     <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
-    <generation type="Random" width="500"/>
-    <link right="playerSpawnHill2.xml"/>
+    <generation type="Random" width="400"/>
     <hill peakx="0" peaky="1000" width="50"/>
+    <link right="001.xml"/>
     <weather>Rainy</weather>
     <time>3400</time>
-    <spawnx>-880</spawnx>
-    <trigger spawnx="-850" id="first" notext="1"/>
-    <npc name="Guy" hasDialog="true" spawnx="0" canMove="false" health="1" x="-582.05096" y="65.998985" dindex="9999"/>
+    <spawnx>-650</spawnx>
+    <trigger spawnx="-630" id="first" notext="1"/>
+    <npc name="Guy" hasDialog="true" spawnx="0" canMove="false"/>
 </World>
 
 <Trigger id="first">Guy</Trigger>
 
 <Dialog name="Guy">
-    <text id="0">
-        <gotox>-600</gotox>
+    <text id="0" nextid="1" pause="true">
+        <gotox playerMove="0" advance="1">-600</gotox>
+    </text>
+    <text id="1">
+        ...
+                                                                                                                                                                                                                                                                <gotox>700</gotox>
+        <set id="Slow" value="0"/>
     </text>
 </Dialog>
diff --git a/xml/001.xml b/xml/001.xml
new file mode 100644 (file)
index 0000000..aeb0a85
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<World>
+    <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
+    <generation type="Random" width="600"/>
+    <link left="000.xml"/>
+    <weather>Rainy</weather>
+</World>
index 94ef9b8cddca668b82d39514da3e38bceac74e6c..534b5d9fb5eee1b2ce69e69e9217ccc58c7cb1b8 100644 (file)
@@ -3,70 +3,24 @@
     <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
     <generation type="Random" width="500"/>
     <link right="playerSpawnHill2.xml"/>
-    <time>12000</time>
     <hill peakx="0" peaky="1000" width="50"/>
-    <rabbit spawnx="300" aggressive="false" maxHealth="100"/>
-    <bird spawny="500" maxHealth="1"/>
-    <cat/>
-    <!--<trigger x="-300" id="Test"/>-->
-    <npc name="Ralph" hasDialog="true" spawnx="300"/>
-    <npc name="Johnny" hasDialog="false" spawnx="300"/>
-    <npc name="Big Dave" hasDialog="true" spawnx="300"/>
-    <page spawnx="-200" id="assets/pages/gootaGoFast.png" cid="canSprint" cvalue="1"/>
-    <page spawnx="-500" id="assets/pages/gootaJump.png" cid="canJump" cvalue="1"/>
-    <village name="Big Dave&apos;s bagel emporium! The greatest place on earth!">
-        <structure type="0" spawnx="-300" inside="playerSpawnHill1_Building1.xml" alive="1"/>
-        <structure type="5" spawnx="-500" alive="1"/>
-        <stall type="market" texture="assets/style/classic/stall.png" alive="1">
-            <text>
-                <greet>Welcome to Smithy's! What would you like to purchase today?</greet>
-                <accept>Thanks!</accept>
-                <deny>Come back with more money to get this item!</deny>
-                <leave>Have a great day, and watch out for my rabbit Mr. Cuddles, he might try to attack you.</leave>
-            </text>
-            <trade quantity="420" item="Dank MayMay" quantity1="1" item1="Wood Sword"/>
-            <trade quantity="666" item="Wood Sword" quantity1="420" item1="Dank MayMay"/>
-        </stall>
-    </village>
+    <weather>Rainy</weather>
+    <time>3400</time>
+    <spawnx>-880</spawnx>
+    <trigger spawnx="-850" id="first" notext="1"/>
+    <npc name="Guy" hasDialog="true" spawnx="0" canMove="false"/>
 </World>
 
-<Trigger id="Test">It was a dark and stormy night...
-Except it was the middle of the day.
-And it wasn't stormy.
-...</Trigger>
+<Trigger id="first">Guy</Trigger>
 
-<Dialog name="Ralph">
+<Dialog name="Guy">
     <text id="0" nextid="1">
-               Hello there! My name is Ralph.
-                                                                                                                                                                                                                                                                                               <gotox>300</gotox>
+        <gotox>-600</gotox>
     </text>
-    <text id="1" nextid="2" call="Johnny" callid="0" pause="true">
-               You should go talk to my friend Johnny. He's a pretty chill dude.
-       </text>
-    <text id="2">
-               Niice.
-                                                                                                                                                                                                                                                                                               <quest check="Your First Quest" fail="3"/></text>
-    <text id="3">
-               Go check out Johnny. He's cool.
-       </text>
-</Dialog>
-
-<Dialog name="Johnny">
-    <text id="0" nextid="1" pause="true">
-               Sup bro! Have a quest. To complete it, just go talk to Ralph again.
-                                                                                                                                                                                                                                                                                               <quest assign="Your First Quest">
-                       Dank MayMay,2
-                       Wood Sword,1
-               </quest>
+    <text id="1">
+               ...
+                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <gotox>1000</gotox>
+        <set id="Slow" value="0"/>
+        <set id="canSprint" value="1"/>
     </text>
-    <text id="1" nextid="1" pause="true">
-               Broooooooooooooo...
-       </text>
-</Dialog>
-
-<Dialog name="Big Dave">
-    <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>
 </Dialog>
index 0b51b552bec4c2f94886fa79eb09d0680189e7d4..50b34e0dd9096bc7d0b5fbb18e6f87469e4eafff 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>