]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
actual game making
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 10 Jun 2016 19:33:02 +0000 (15:33 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 10 Jun 2016 19:33:02 +0000 (15:33 -0400)
13 files changed:
brice.dat
include/mob.hpp
include/world.hpp
main.cpp
shaders/world.frag
src/brice.cpp
src/entities.cpp
src/mob.cpp
src/ui.cpp
src/world.cpp
xml/000.xml [new file with mode: 0644]
xml/playerSpawnHill1.xml
xml/playerSpawnHill1_Building1.xml

index ea71945339f7a7cd6d35324a11df49578bb93bfc..3b090ad887b4d2aa51cf2d99adc0eeaf055a2798 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,7 @@
-2
+3
 canSprint
 0
 canJump
 0
+Slow
+1
index 0dd50ac1d32f712d85bc763e7fe472d48b230c07..7ef4ff98b52bed53b3c14d38db411d6cb6b3721d 100644 (file)
@@ -115,6 +115,8 @@ private:
     std::string id;
     bool triggered;
 public:
+       bool notext;
+
     Trigger(void);
 
     void act(void);
index fa8e4d8c2830e1cf0d474ace6219d777e73e6aa1..e240973f294f53f8c146d2430a7b519a11dd3f02 100644 (file)
@@ -27,8 +27,7 @@ enum class WorldBGType : unsigned int {
  * Weather is set by the world somewhere.
  */
 enum class WorldWeather : unsigned char {
-       Sunny = 0,      /**< Sunny/daytime */
-       Dark,           /**< Nighttime */
+       None = 0,       /**< None (sunny) */
        Rain,           /**< Rain */
        Snowy           /**< Snow */
 };
@@ -265,6 +264,7 @@ protected:
         * @see addStructure()
         * @see getStructurePos()
         */
+       std::vector<Structures *> build;
 
        /**
         * A vector of all villages in the world.
@@ -291,7 +291,6 @@ protected:
 
 public:
 
-       std::vector<Structures *> build;
        /**
         * A vector of pointers to all entities from the other vectors.
         * This is used to mass-manage entities, or operate on entities
@@ -349,7 +348,7 @@ public:
        /**
         * Updates entity positions, time of day, and music.
         */
-       void update(Player *p, unsigned int delta, unsigned int ticks);
+       void update(Player *p, unsigned int delta);
 
        /**
         * Gets the width of the world, presumably in pixels.
@@ -417,6 +416,9 @@ public:
        std::string getWeatherStr(void) const;
        const WorldWeather& getWeatherId(void) const;
 
+       // sets the weatherrrr
+       void setWeather(const std::string& w);
+
        // sets / gets pathnames of XML files for worlds to the left and right
        std::string setToLeft(std::string file);
        std::string setToRight(std::string file);
index 4dac3b8e362cebe27f797624fcaf130421e9c12a..9c0ba2fee093af7599a8d375b0d1ce79ea80fbc2 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -20,6 +20,8 @@ using namespace tinyxml2;
 #include <ui.hpp>
 #include <gametime.hpp>
 
+#include <fstream>
+
 /* ----------------------------------------------------------------------------
 ** Variables section
 ** --------------------------------------------------------------------------*/
@@ -118,7 +120,7 @@ void mainLoop(void);
 int main(int argc, char *argv[])
 {
        static SDL_GLContext mainGLContext = NULL;
-       static bool worldReset = false;
+       static bool worldReset = false, worldDontReallyRun = false;
 
        // handle command line arguments
        if (argc > 1) {
@@ -129,6 +131,8 @@ int main(int argc, char *argv[])
                for (const auto &s : args) {
                        if (s == "--reset" || s == "-r")
                                worldReset = true;
+                       else if (s == "--dontrun" || s == "-d")
+                               worldDontReallyRun = true;
                }
        }
 
@@ -286,8 +290,14 @@ int main(int argc, char *argv[])
                }
 
                game::briceClear();
+
+               std::ofstream pdat ("xml/.main.dat", std::ios::out);
+               pdat.close();
        }
 
+       if (worldDontReallyRun)
+               return 0;
+
        if (currentWorld == nullptr) {
                
                // load the first valid XML file for the world
@@ -372,7 +382,7 @@ void mainLoop(void){
                if (game::time::tickHasPassed())
                        logic();
 
-               currentWorld->update(player, game::time::getDeltaTime(), game::time::getTickCount());
+               currentWorld->update(player, game::time::getDeltaTime());
                currentWorld->detect(player);
        }
 }
index bde5fa53176670635ed2da7ebe9fe6807741d654..617cbb1ce777852ea690030a546f3b7379117bdd 100644 (file)
@@ -23,10 +23,12 @@ void main()
                for (int i = 0; i < lightSize; i++) {
                        vec2 loc = light[i].xy;
                        float dist = length(loc - fragCoord.xy);
-                       float attenuation = clamp(1.0f - dist*dist/(light[i].w*light[i].w), 0.0f, 1.0f);
-                       attenuation *= attenuation;
+                       if (dist < light[i].w) {
+                               float attenuation = clamp(1.0f - dist*dist/(light[i].w*light[i].w), 0.0f, 1.0f);
+                               attenuation *= attenuation;
 
-                       shadeColor += (vec4(attenuation, attenuation, attenuation, 0.0f) * vec4(lightColor[i])) * lightImpact;          
+                               shadeColor += (vec4(attenuation, attenuation, attenuation, 0.0f) * vec4(lightColor[i])) * lightImpact;
+                       }
                }
        }
        shadeColor += ambientLight;
index d5ac46dc31a008569db4abeb282b1562b033f3de..de95f51e54ffa0290fe35602c24378d96891d4cb 100644 (file)
@@ -35,8 +35,10 @@ namespace game {
 
        void briceClear(void) {
                std::ofstream out ("brice.dat", std::ios::out);
+               const std::string defaultt = "1\nSlow\n1\n";
+               out.write(defaultt.data(), defaultt.size());
                out.close();
-               brice.clear();
+               briceLoad();
        }
 
        void briceSave(void) {
index 01255d56e4d88333f6fa969e7666f6837ff9b920..9f9a47cb756c204e21592d8649532517b6290d23 100644 (file)
@@ -257,6 +257,10 @@ void NPC::createFromXML(XMLElement *e, World *w=nullptr)
     // custom health value
        E_LOAD_HEALTH;
 
+       // movemenet
+       if (e->QueryBoolAttribute("canMove", &dialog) == XML_NO_ERROR)
+               canMove = dialog;
+
        // dialog index
        if (e->QueryUnsignedAttribute("dindex", &flooor) == XML_NO_ERROR)
                dialogIndex = flooor;
@@ -591,8 +595,10 @@ wander(int timeRun)
                        vel.x = HLINES(-0.018);
                else if (loc.x < targetx - HLINES(5))
                        vel.x = HLINES(0.018);
-               else
+               else {
                        targetx = 0.9112001f;
+                       vel.x = 0;
+               }
        } else if (ticksToUse == 0) {
                ticksToUse = timeRun;
 
@@ -628,6 +634,7 @@ void NPC::interact() { //have the npc's interact back to the player
                XMLElement *exml,*oxml;
 
                static unsigned int oldidx = 9999;
+               const char *ptr;
                std::string nname;
                unsigned int idx;
                bool stop;
@@ -704,8 +711,11 @@ COMMONAIFUNC:
                                moveTo(std::stoi(oxml->GetText()));
 
                        // asdlfkj
-                       auto ptr = exml->GetText() - 1;
-                       while (isspace(*++ptr));
+                       if (exml->GetText() == nullptr)
+                               goto OTHERSTUFF;
+
+                       ptr = exml->GetText() - 1;
+                       while (*++ptr && isspace(*ptr));
 
                        // handle dialog options
                        if ((oxml = exml->FirstChildElement("option"))) {
@@ -736,6 +746,8 @@ COMMONAIFUNC:
                                ui::waitForDialog();
                        }
 
+OTHERSTUFF:
+
                        // trigger other npcs if desired
                        if (!(nname = exml->StrAttribute("call")).empty()) {
                                NPC *n = *std::find_if(std::begin(currentWorld->npc), std::end(currentWorld->npc), [nname](NPC *npc) {
@@ -1062,7 +1074,7 @@ bool Particles::timeUp(void)
 
 void Player::save(void) {
        std::string data;
-       std::ofstream out ("xml/main.dat",std::ios::out | std::ios::binary);
+       std::ofstream out (xmlFolder + ".main.dat", std::ios::out | std::ios::binary);
        std::cout<<"Saving player data..."<<std::endl;
        data.append(std::to_string((int)loc.x) + "\n");
        data.append(std::to_string((int)loc.y) + "\n");
@@ -1088,7 +1100,7 @@ void Player::save(void) {
 void Player::sspawn(float x,float y) {
        unsigned int i;
        int count;
-       std::ifstream in (std::string(xmlFolder + "main.dat"),std::ios::in | std::ios::binary);
+       std::ifstream in (xmlFolder + ".main.dat", std::ios::in | std::ios::binary);
        spawn(x,y);
 
        if (in.good()) {
index 7701086c84009723aea75092adbc2417485fa42a..798f09a7cb630f3391a87a7e528fa145b1d9a432 100644 (file)
@@ -331,6 +331,7 @@ Trigger::Trigger(void) : Mob()
     height = 2000;
     //tex = TextureIterator();
     triggered = false;
+       notext = false;
 }
 
 void Trigger::act(void)
@@ -355,28 +356,38 @@ void Trigger::act(void)
 
             player->vel.x = 0;
 
-                       if (exml == nullptr) {
+                       if (notext) {
+                               for (auto &n : currentWorld->npc) {
+                                       if (n->name == exml->GetText()) {
+                                               n->interact();
+                                               break;
+                                       }
+                               }
+                       } else {
+
+                       /*if (exml == nullptr) {
                                auto id = xmle->StrAttribute("cid");
                                if (!id.empty()) {
                                        game::setValue(id, xmle->StrAttribute("cvalue"));
                                        game::briceUpdate();
                                }
                                return;
-                       }
+                       }*/
 
-            ui::toggleBlackFast();
-            ui::waitForCover();
+                   ui::toggleBlackFast();
+                   ui::waitForCover();
 
-            std::string text = exml->GetText();
-            char *pch = strtok(&text[0], "\n");
+               std::string text = exml->GetText();
+                   char *pch = strtok(&text[0], "\n");
 
-            while (pch) {
-                ui::importantText(pch);
-                ui::waitForDialog();
-                pch = strtok(NULL, "\n");
-            }
+                   while (pch) {
+                       ui::importantText(pch);
+                       ui::waitForDialog();
+                       pch = strtok(NULL, "\n");
+                   }
 
-            ui::toggleBlackFast();
+               ui::toggleBlackFast();
+                       }
 
             triggered = true;
             running = false;
@@ -397,10 +408,17 @@ bool Trigger::bindTex(void)
 void Trigger::createFromXML(XMLElement *e, World *w=nullptr)
 {
        (void)w;
-    float Xlocx;
-    if (e->QueryFloatAttribute("x", &Xlocx) == XML_NO_ERROR)
-        loc.x = Xlocx;
-    id = e->StrAttribute("id");
+       float Xlocx;
+
+       if (e->QueryFloatAttribute("spawnx", &Xlocx) == XML_NO_ERROR)
+               loc.x = Xlocx;
+
+       if (e->QueryBoolAttribute("notext", &notext) != XML_NO_ERROR)
+               notext = false;
+
+       id = e->StrAttribute("id");
+
+       xmle = e;
 }
 
 void Trigger::saveToXML(void)
index f32bc79c9869526163aabf56738ea8a3582329cd..c5d134e87e287890b3dadb3d9fda2fcc62d4d8b1 100644 (file)
@@ -1256,6 +1256,8 @@ EXIT:
                                                if (fadeEnable)
                                                        break;
                                                player->vel.x = -PLAYER_SPEED_CONSTANT;
+                                               if (std::stoi(game::getValue("Slow")) == 1)
+                                                       player->vel.x /= 2.0f;
                                                player->left = left = true;
                                                player->right = right = false;
                                                if (currentWorldToLeft) {
@@ -1270,6 +1272,8 @@ EXIT:
                                                if (fadeEnable)
                                                        break;
                                                player->vel.x = PLAYER_SPEED_CONSTANT;
+                                               if (std::stoi(game::getValue("Slow")) == 1)
+                                                       player->vel.x /= 2.0f;
                                                player->right = right = true;
                                                player->left = left = false;
                                                if (currentWorldToRight) {
index a36a9b84346b2f8daf2d3b90b3cd7f4ccf9eae9f..2eebc4a499fff2941a2eecae399bcdf3375c9e2b 100644 (file)
@@ -31,6 +31,12 @@ extern World       *currentWorldToRight;     // main.cpp
 extern bool         inBattle;               // ui.cpp?
 extern std::string  xmlFolder;
 
+static const std::array<std::string, 3> WorldWeatherString {
+       "None",
+       "Rainy",
+       "Snowy"
+};
+
 // particle mutex
 std::mutex partMutex;
 
@@ -220,7 +226,7 @@ generate(int width)
                s.y = (randGet() % game::SCREEN_HEIGHT) + 100;
        }
 
-       weather = WorldWeather::Sunny;
+       weather = WorldWeather::None;
 }
 
 /**
@@ -1010,16 +1016,8 @@ detect(Player *p)
  * Also handles music fading, although that could probably be placed elsewhere.
  */
 void World::
-update(Player *p, unsigned int delta, unsigned int ticks)
+update(Player *p, unsigned int delta)
 {
-       // update day/night time
-       if (!(ticks % DAY_CYCLE) || ticks == 0) {
-               if (weather == WorldWeather::Sunny)
-                       weather = WorldWeather::Dark;
-               else if (weather == WorldWeather::Dark)
-                       weather = WorldWeather::Sunny;
-       }
-
     // update player coords
        p->loc.y += p->vel.y                     * delta;
        p->loc.x +=(p->vel.x * p->speed) * delta;
@@ -1230,21 +1228,7 @@ void World::setStyle(std::string pre)
  */
 std::string World::getWeatherStr(void) const
 {
-       switch (weather) {
-       case WorldWeather::Sunny:
-               return "Sunny";
-               break;
-       case WorldWeather::Dark:
-               return "Dark";
-               break;
-       case WorldWeather::Rain:
-               return "Rainy";
-               break;
-       case WorldWeather::Snowy:
-               return "Snowy";
-               break;
-       }
-       return "???";
+       return WorldWeatherString[static_cast<int>(weather)];
 }
 
 const WorldWeather& World::getWeatherId(void) const
@@ -1252,6 +1236,17 @@ const WorldWeather& World::getWeatherId(void) const
        return weather;
 }
 
+void World::setWeather(const std::string &s)
+{
+       for (unsigned int i = WorldWeatherString.size(); i--;) {
+               if (WorldWeatherString[i] == s) {
+                       weather = static_cast<WorldWeather>(i);
+                       return;
+               }
+       } 
+       weather = WorldWeather::None;
+}
+
 /**
  * Pretty self-explanatory.
  */
@@ -2008,6 +2003,16 @@ loadWorldFromXMLNoSave(std::string path) {
             }
                }
 
+               // weather tags
+               else if (name == "weather") {
+                       tmp->setWeather(wxml->GetText());
+               }
+
+               // set spawn x for player
+               else if (name == "spawnx") {
+                       player->loc.x = std::stoi(wxml->GetText());
+               }
+
         // mob creation
         else if (name == "rabbit") {
             newEntity = new Rabbit();
@@ -2054,8 +2059,6 @@ loadWorldFromXMLNoSave(std::string path) {
                if (newEntity != nullptr) {
                        bool alive = true;
                        if (wxml->QueryBoolAttribute("alive", &alive) != XML_NO_ERROR || alive) {
-                               newEntity->createFromXML(wxml, tmp);
-
                                switch (newEntity->type) {
                                case NPCT:
                                        tmp->addNPC(dynamic_cast<NPC *>(newEntity));
@@ -2069,6 +2072,8 @@ loadWorldFromXMLNoSave(std::string path) {
                                default:
                                        break;
                                }
+
+                               newEntity->createFromXML(wxml, tmp);
                        }
                }
 
diff --git a/xml/000.xml b/xml/000.xml
new file mode 100644 (file)
index 0000000..9996cec
--- /dev/null
@@ -0,0 +1,20 @@
+<?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"/>
+    <hill peakx="0" peaky="1000" width="50"/>
+    <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"/>
+</World>
+
+<Trigger id="first">Guy</Trigger>
+
+<Dialog name="Guy">
+    <text id="0">
+        <gotox>-600</gotox>
+    </text>
+</Dialog>
index f16b5118644df8a840cb15b526921aeb6e4c1652..94ef9b8cddca668b82d39514da3e38bceac74e6c 100644 (file)
@@ -5,13 +5,13 @@
     <link right="playerSpawnHill2.xml"/>
     <time>12000</time>
     <hill peakx="0" peaky="1000" width="50"/>
-    <rabbit spawnx="300" aggressive="false" maxHealth="100" health="50"/>
-    <bird spawny="500" x="-534.19525" y="712.36743" health="1"/>
-    <cat x="-48.600014" y="64.996986" alive="1"/>
+    <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" health="1" x="-22.480118" y="64.996986" dindex="0"/>
-    <npc name="Johnny" hasDialog="false" spawnx="300" health="1" x="639.87152" y="68.796982" dindex="9999"/>
-    <npc name="Big Dave" hasDialog="true" spawnx="300" health="1" x="794.33545" y="69.796974" dindex="0"/>
+    <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!">
@@ -37,14 +37,15 @@ And it wasn't stormy.
 
 <Dialog name="Ralph">
     <text id="0" nextid="1">
-               Hello there! My name is Ralph.                                                                                                                                                                                                                                                                                                                                                                                                  <gotox>300</gotox>
+               Hello there! My name is Ralph.
+                                                                                                                                                                                                                                                                                               <gotox>300</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>
+                                                                                                                                                                                                                                                                                               <quest check="Your First Quest" fail="3"/></text>
     <text id="3">
                Go check out Johnny. He's cool.
        </text>
@@ -53,9 +54,9 @@ And it wasn't stormy.
 <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 assign="Your First Quest">
+                       Dank MayMay,2
+                       Wood Sword,1
                </quest>
     </text>
     <text id="1" nextid="1" pause="true">
@@ -64,8 +65,8 @@ And it wasn't stormy.
 </Dialog>
 
 <Dialog name="Big Dave">
-    <text id="0" pause="true">
+    <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 eb63d7be21091bc92c0cf578c86d3d3a11e4680f..0b51b552bec4c2f94886fa79eb09d0680189e7d4 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>