]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
reenabled dialog, fixed going inside
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 25 Nov 2016 18:01:08 +0000 (13:01 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 25 Nov 2016 18:01:08 +0000 (13:01 -0500)
include/components.hpp
include/world.hpp
src/components.cpp
src/engine.cpp
src/ui.cpp
src/world.cpp
xml/!town.xml
xml/!town2.xml
xml/bobshouse.xml

index f2e040d69a075bdc2f8775ac3c40ea9ab597bff0..1c83a344b35f0acf21ec52c9aa2565ebde459f63 100644 (file)
@@ -232,9 +232,10 @@ struct Visible {
 
 struct Dialog {
        Dialog(int idx = 0)
-               : index(idx) {}
+               : index(idx), rindex((idx == 9999) ? randGet() : idx) {}
 
        int index;
+       int rindex;
 };
 
 /**
index 8d88e5a34b99b8946f8be5d60ab1f12c0e0f5698..308222d497238a623a34a0e29b9843b9e5ad37b9 100644 (file)
@@ -1,24 +1,27 @@
-#ifndef WORLD_H
-#define WORLD_H
-
 /**
  * @file  world.hpp
  * @brief The world system
  */
 
+#ifndef WORLD_H
+#define WORLD_H
+
+// library includes
+#include <entityx/entityx.h>
+
 // local game includes
 #include <common.hpp>
 #include <coolarray.hpp>
 #include <events.hpp>
 #include <texture.hpp>
-#include <tinyxml2.h>
 #include <components.hpp>
+#include <tinyxml2.h>
+
 using namespace tinyxml2;
 
 /**
  * The background type enum.
- * This enum contains all different possibilities for world backgrounds; used
- * in World::setBackground() to select the appropriate images.
+ * Used to choose which set of background images should be used.
  */
 enum class WorldBGType : unsigned int {
        Forest = 0      /**< A forest theme. */
@@ -35,6 +38,15 @@ enum class WorldWeather : unsigned char {
        Snowy           /**< Snow */
 };
 
+/**
+ * Strings to represent each type of weather.
+ */
+constexpr const char* WorldWeatherString[3] = {
+       "None",
+       "Rainy",
+       "Snowy"
+};
+
 /**
  * The line structure.
  * This structure is used to store the world's ground, stored in vertical
@@ -54,13 +66,9 @@ typedef struct {
  */
 extern int worldShade;
 
-/**
- * The file path to the currently loaded XML file.
- */
-extern std::string currentXML;
-
 /**
  * Defines how many game ticks it takes to go from day to night or vice versa.
+ * Technically a half day cycle...
  */
 constexpr const unsigned int DAY_CYCLE = 10000;
 
@@ -87,53 +95,76 @@ constexpr const unsigned int INDOOR_FLOOR_HEIGHTT = 400;
  */
 constexpr const unsigned int INDOOR_FLOOR_HEIGHT = (INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS);
 
-#include <entityx/entityx.h>
-
-constexpr const char* WorldWeatherString[3] = {
-       "None",
-       "Rainy",
-       "Snowy"
-};
-
+/**
+ * World data.
+ * Contains all necessary data for a world. An instance of this is kept in the
+ * world system, and is populated through it's load() function.
+ */
 struct WorldData2 {
-       // data
-       std::vector<WorldData> data;
-       float startX;
 
-       // indoor
-       bool indoor;
-       float indoorWidth;
-       GLuint indoorTex;
+       // Data variables
+       std::vector<WorldData> data; /**< The world's ground data. */
+       float startX;                /**< The furthest left coordinate of the world. */
 
-       // links
-       std::string toLeft, toRight;
+       // Indoor variables
+       bool indoor;                 /**< Set to true if this is an indoor world. */
+       float indoorWidth;           /**< The width of the indoor texture (house). */
+       GLuint indoorTex;            /**< The texture to draw (house). */
+       std::string outdoor;         /**< The file name of the outdoor world. */
+       vec2 outdoorCoords;          /**< The coordinates the player should spawn to when exiting. */
 
-       // style
-       WorldBGType style;
-       std::string styleFolder;
-       std::vector<std::string> sTexLoc;
+       // World linkage
+       std::string toLeft, toRight; /**< File names of the worlds adjacent to this one. */
 
-       // music
-       std::string bgm;
+       // Style variables
+       WorldBGType style;                /**< The style type of the world. */
+       std::string styleFolder;          /**< The folder to get stylized textures from. */
+       std::vector<std::string> sTexLoc; /**< File names of stylized textures for structures. */
 
-       // village
-       float villageStart, villageEnd;
+       // Music
+       std::string bgm;             /**< The path to the BGM file. */
 };
 
+/**
+ * The world system
+ * Does everything needed to take care of the world.
+ */
 class WorldSystem : public entityx::System<WorldSystem>, public entityx::Receiver<WorldSystem> {
 private:
+
+       /**
+        * The world's data.
+        */
        WorldData2 world;
 
+       /**
+        * The current state of weather in the world.
+        */
        WorldWeather weather;
 
+       /**
+        * SDL's object for handling the background music.
+        */
        Mix_Music *bgmObj;
 
+       /**
+        * Paths of files to get stylized textures from.
+        */
        std::vector<std::string> bgFiles;
 
+       /**
+        * Allows for iteration between background textures, for rendering.
+        */
        TextureIterator bgTex;
 
+       /**
+        * An object to handle and parse world XML files.
+        */
        XMLDocument xmlDoc;
 
+       /**
+        * The file path to the currently loaded world.
+        */
        std::string currentXMLFile;
 
 public:
@@ -183,29 +214,4 @@ public:
        void load(const std::string& file);
 };
 
-/**
- * Constructs an XML object for accessing/modifying the current world's XML
- * file.
- */
-const XMLDocument& loadWorldXML(void);
-
-/**
- * Loads the player into the world created by the given XML file. If a world is
- * already loaded it will be saved before the transition is made.
- */
-World *loadWorldFromXML(std::string path);
-
-/**
- * Loads the player into the XML-scripted world, but does not save data from the
- * previous world if one was loaded.
- */
-World *loadWorldFromXMLNoSave(std::string path);
-World *loadWorldFromXMLNoTakeover(std::string path);
-
-/**
- * Loads a world using a pointer to the current world (used for loading adjacent
- * worlds that have already been read into memory.
- */
-World *loadWorldFromPtr(World *ptr);
-
 #endif // WORLD_H
index f216cd22931238f372293ef91654731eb067b31b..7c6091ed0299b81105d23e3098a038d1fb7a85bb 100644 (file)
@@ -7,6 +7,9 @@
 #include <ui.hpp>
 #include <engine.hpp>
 #include <world.hpp>
+#include <brice.hpp>
+
+static std::vector<std::string> randomDialog (readFileA("assets/dialog_en-us"));
 
 void MovementSystem::update(entityx::EntityManager &en, entityx::EventManager &ev, entityx::TimeDelta dt)
 {
@@ -99,155 +102,6 @@ void RenderSystem::update(entityx::EntityManager &en, entityx::EventManager &ev,
        });
 }
 
-/*
-void Entity::draw(void)
-{
-       GLfloat tex_coord[] = {0.0, 0.0,
-                                                  1.0, 0.0,
-                                                  1.0, 1.0,
-
-                                                  1.0, 1.0,
-                                                  0.0, 1.0,
-                                                  0.0, 0.0};
-
-       GLfloat tex_coordL[] = {1.0, 0.0,
-                                                       0.0, 0.0,
-                                                       0.0, 1.0,
-
-                                                       0.0, 1.0,
-                                                       1.0, 1.0,
-                                                       1.0, 0.0};
-
-       GLfloat coords[] = {loc.x, loc.y, z,
-                                               loc.x + width, loc.y, z,
-                                               loc.x + width, loc.y + height, z,
-
-                                               loc.x + width, loc.y + height, z,
-                                               loc.x, loc.y + height, z,
-                                               loc.x, loc.y, z};
-
-
-       glActiveTexture(GL_TEXTURE0);
-
-       if (!alive)
-               return;
-
-       if (type == NPCT) {
-               NPCp(this)->drawThingy();
-
-               if (gender == MALE)
-                       glColor3ub(255, 255, 255);
-               else if (gender == FEMALE)
-                       glColor3ub(255, 105, 180);
-       } else if (type == MOBT) {
-               if (Mobp(this)->rider != nullptr) {
-                       Mobp(this)->rider->loc.x = loc.x + width * 0.25f;
-               Mobp(this)->rider->loc.y = loc.y + height - HLINES(5);
-               Mobp(this)->rider->vel.y = .12;
-                       Mobp(this)->rider->z     = z + 0.01;
-           }
-       }
-       switch(type) {
-       case PLAYERT:
-               static int texState = 0;
-               if (speed && !(game::time::getTickCount() % ((2.0f/speed) < 1 ? 1 : (int)((float)2.0f/(float)speed)))) {
-                       if (++texState == 9)
-                               texState = 1;
-                       glActiveTexture(GL_TEXTURE0);
-                       tex(texState);
-               }
-               if (!ground) {
-                       glActiveTexture(GL_TEXTURE0);
-                       tex(0);
-               } else if (vel.x) {
-                       glActiveTexture(GL_TEXTURE0);
-                       tex(texState);
-               } else {
-                       glActiveTexture(GL_TEXTURE0);
-                       tex(0);
-               }
-               break;
-       case MOBT:
-               if (!Mobp(this)->bindTex())
-                       goto NOPE;
-               break;
-       case STRUCTURET:
-       default:
-               glActiveTexture(GL_TEXTURE0);
-               tex(0);
-               break;
-       }
-
-       Render::worldShader.use();
-       // make the entity hit flash red
-       if (maxHitDuration-hitDuration) {
-               float flashAmt = 1-(hitDuration/maxHitDuration);
-               glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, flashAmt, flashAmt, 1.0);
-       }
-
-       glUniform1i(Render::worldShader.uniform[WU_texture], 0);
-       Render::worldShader.enable();
-
-       glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coords);
-       if (left)
-               glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coordL);
-       else
-               glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0 ,tex_coord);
-       glDrawArrays(GL_TRIANGLES, 0, 6);
-
-       glUniform4f(Render::worldShader.uniform[WU_tex_color], 1.0, 1.0, 1.0, 1.0);
-NOPE:
-if (near && type != MOBT)
-       ui::putStringCentered(loc.x+width/2,loc.y-ui::fontSize-game::HLINE/2,name);
-if (health != maxHealth) {
-
-       static GLuint frontH = Texture::genColor(Color(255,0,0));
-       static GLuint backH =  Texture::genColor(Color(150,0,0));
-       glUniform1i(Render::worldShader.uniform[WU_texture], 0);
-
-       GLfloat coord_back[] = {
-               loc.x,                  loc.y + height,                               z + 0.1f,
-               loc.x + width,  loc.y + height,                               z + 0.1f,
-               loc.x + width,  loc.y + height + game::HLINE * 2, z + 0.1f,
-
-               loc.x + width,  loc.y + height + game::HLINE * 2, z + 0.1f,
-               loc.x,                  loc.y + height + game::HLINE * 2, z + 0.1f,
-               loc.x,                  loc.y + height,                               z + 0.1f,
-       };
-
-       GLfloat coord_front[] = {
-               loc.x,                                      loc.y + height,                   z,
-               loc.x + health / maxHealth * width, loc.y + height,                   z,
-               loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, z,
-
-               loc.x + health / maxHealth * width, loc.y + height + game::HLINE * 2, z,
-               loc.x,                              loc.y + height + game::HLINE * 2, z,
-               loc.x,                              loc.y + height,                   z,
-       };
-
-       glBindTexture(GL_TEXTURE_2D, backH);
-       GLfloat tex[] = { 0.0, 0.0,
-                                         1.0, 0.0,
-                                         1.0, 1.0,
-
-                                         1.0, 1.0,
-                                         0.0, 1.0,
-                                         0.0, 0.0,
-       };
-       glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coord_back);
-       glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
-       glDrawArrays(GL_TRIANGLES, 0, 6);
-
-       glBindTexture(GL_TEXTURE_2D, frontH);
-       glVertexAttribPointer(Render::worldShader.coord, 3, GL_FLOAT, GL_FALSE, 0, coord_front);
-       glVertexAttribPointer(Render::worldShader.tex, 2, GL_FLOAT, GL_FALSE, 0, tex);
-       glDrawArrays(GL_TRIANGLES, 0, 6);
-}
-
-Render::worldShader.disable();
-Render::worldShader.unuse();
-}*/
-
 void DialogSystem::configure(entityx::EventManager &ev)
 {
        ev.subscribe<MouseClickEvent>(*this);
@@ -267,7 +121,10 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                auto exml = game::engine.getSystem<WorldSystem>()->getXML()->FirstChildElement("Dialog");
                                int newIndex;
 
-                               if (exml != nullptr) {
+                               if (d.index == 9999) {
+                                       ui::dialogBox(name.name, "", false, randomDialog[d.rindex % randomDialog.size()]);
+                                       ui::waitForDialog();
+                               } else if (exml != nullptr) {
                                        while (exml->StrAttribute("name") != name.name)
                                                exml = exml->NextSiblingElement();
 
@@ -275,12 +132,22 @@ void DialogSystem::receive(const MouseClickEvent &mce)
                                        while (exml->IntAttribute("id") != d.index)
                                                exml = exml->NextSiblingElement();
 
-                                       auto cxml = exml->FirstChildElement("content");
-                                       if (cxml == nullptr)
-                                               return;
+                                       auto oxml = exml->FirstChildElement("set");
+                                       if (oxml != nullptr) {
+                                               do game::setValue(oxml->StrAttribute("id"), oxml->StrAttribute("value"));
+                                               while ((oxml = oxml->NextSiblingElement()));
+                                               game::briceUpdate();
+                                       }
+
 
-                                       auto content = cxml->GetText() - 1;
-                                       while (*++content && isspace(*content));
+                                       auto cxml = exml->FirstChildElement("content");
+                                       const char *content;
+                                       if (cxml == nullptr) {
+                                               content = randomDialog[d.rindex % randomDialog.size()].c_str();
+                                       } else {
+                                               content = cxml->GetText() - 1;
+                                               while (*++content && isspace(*content));
+                                       }
 
                                        ui::dialogBox(name.name, "", false, content);
                                        ui::waitForDialog();
index 152e3a4c69effb18447b6feb08778faedc2b8f37..2aa19b06ffb9ab71c14c218147838feabd2605e0 100644 (file)
@@ -49,7 +49,7 @@ void Engine::update(entityx::TimeDelta dt)
 {
     systems.update<InputSystem>(dt);
        systems.update<MovementSystem>(dt);
-       //systems.update<DialogSystem>(dt);
+       systems.update<DialogSystem>(dt);
        systems.update<WorldSystem>(dt);
     systems.update<PlayerSystem>(dt);
 }
index 922e5be5ae4d302853d851a5c343e17b87cb2b58..40339a08fe83a4deec3353b7ef78933603ef4e25 100644 (file)
@@ -575,9 +575,11 @@ namespace ui {
        }
 
        void waitForCover(void) {
-               fadeIntensity = 0;
-               while (fadeIntensity < 255);
-               fadeIntensity = 255;
+               auto& fi = fadeIntensity;
+               fi = 0;
+               while (fi < 255)
+                       std::this_thread::sleep_for(std::chrono::milliseconds(1));
+               fi = 255;
        }
 
        void waitForUncover(void) {
@@ -905,6 +907,7 @@ namespace ui {
 
                                drawNiceBox(vec2 {x, y}, vec2 {x + SCREEN_WIDTH - HLINES(16), y - SCREEN_HEIGHT / 4}, -7.0);
 
+                               setFontZ(-7.2f);
                                rtext = typeOut(dialogBoxText);
                                putString(x + HLINES(2), y - fontSize - game::HLINE, rtext);
 
index 143e1050b4637b2fb60e2dad0853fcc9a5f17394..a0c5641455a475411ab3397ad56e863294704a61 100644 (file)
@@ -105,9 +105,6 @@ static const float bgDraw[4][3]={
        { 255, 255, 0.1  }
 };
 
-std::string currentXMLRaw;
-XMLDocument currentXMLDoc;
-
 /* ----------------------------------------------------------------------------
 ** Functions section
 ** --------------------------------------------------------------------------*/
@@ -221,11 +218,8 @@ void WorldSystem::load(const std::string& file)
 
        world.toLeft = world.toRight = "";
        currentXMLFile = file;
-       std::cout << "ka" << std::endl;
        game::entities.reset();
-       std::cout << "CHOW!!!" << std::endl;
        game::engine.getSystem<PlayerSystem>()->create();
-       std::cout << "chow cow" << std::endl;
 
        // iterate through tags
        while (wxml) {
@@ -294,8 +288,6 @@ void WorldSystem::load(const std::string& file)
                else {
                        auto cxml = xmlDoc.FirstChildElement(tagName.c_str());
                        if (cxml != nullptr) {
-                               DEBUG_printf("Using custom tag <%s>\n", tagName.c_str());
-
                                entity = game::entities.create();
                                auto abcd = cxml->FirstChildElement();
 
@@ -329,7 +321,7 @@ void WorldSystem::load(const std::string& file)
                                                if (abcd->Attribute("value") != nullptr) {
                                                        dim = str2coord(abcd->StrAttribute("value"));
                                                } else {
-                                                       dim = entity.component<Sprite>().get()->getSpriteSize();        
+                                                       dim = entity.component<Sprite>().get()->getSpriteSize() * game::HLINE;
                                                }
                                                
                                                float cdat[2] = {dim.x, dim.y};
@@ -362,7 +354,7 @@ void WorldSystem::load(const std::string& file)
                                        } else if (tname == "Name") {
                                                entity.assign<Name>(coalesce(wxml->Attribute("name"), abcd->Attribute("value"))); 
                                        } else if (tname == "Dialog") {
-                                               entity.assign<Dialog>();
+                                               entity.assign<Dialog>((wxml->BoolAttribute("hasDialog") ? 0 : 9999));
                                        } else if (tname == "Grounded") {
                                                entity.assign<Grounded>();
                                        }
@@ -1193,6 +1185,7 @@ void WorldSystem::detect(entityx::TimeDelta dt)
 void WorldSystem::goWorldRight(Position& p, Solid &d)
 {
        if (!(world.toRight.empty()) && (p.x + d.width > world.startX * -1 - HLINES(15))) {
+       BREAKPOINT;
                ui::toggleBlack();
                ui::waitForCover();
                auto file = world.toRight;
@@ -1215,18 +1208,31 @@ void WorldSystem::goWorldLeft(Position& p)
 
 void WorldSystem::goWorldPortal(Position& p)
 {
-       game::entities.each<Position, Sprite, Portal>(
-               [&](entityx::Entity entity, Position& loc, Sprite &sprite, Portal &portal) {
-                       (void)entity;
-
-                       auto& size = sprite.sprite.front().first.size;
-                       if (!(portal.toFile.empty()) && p.x > loc.x && p.x < loc.x + size.x)  {
-                               ui::toggleBlack();
-                               ui::waitForCover();
-                               load(portal.toFile);
-                               ui::toggleBlack();
-                               return;
+       std::string file;
+
+       if (world.indoor) {
+               file = world.outdoor;
+               p.x = world.outdoorCoords.x; // ineffective, player is regen'd
+               p.y = world.outdoorCoords.y;
+       } else {
+               game::entities.each<Position, Solid, Portal>(
+                       [&](entityx::Entity entity, Position& loc, Solid &dim, Portal &portal) {
+                               (void)entity;
+                               if (!(portal.toFile.empty()) && p.x > loc.x && p.x < loc.x + dim.width)  {
+                                       file = portal.toFile;
+                                       world.outdoor = currentXMLFile;
+                                       world.outdoorCoords = vec2(loc.x + dim.width / 2, 100);
+                                       return;
+                               }
                        }
-               }
-       );
+               );
+       }
+
+       if (!file.empty()) {
+               std::cout << file << std::endl;
+               ui::toggleBlack();
+               ui::waitForCover();
+               load(file);
+               ui::toggleBlack();
+       }
 }
index 20b5ca479fad3713578e4524e0ec57bab49f880c..1e193fb16d1699e357deba242f3876d6a1117149 100644 (file)
@@ -1,12 +1,11 @@
 <?xml version="1.0"?>
-
-<include file="entities.xml" />
+<include file="entities.xml"/>
 
 <World>
     <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
     <generation width="1600"/>
     <time>6000</time>
-    <link right="!town2.xml" />
+    <link right="!town2.xml"/>
     <spawnx>-300</spawnx>
     <npc name="Sanc" hasDialog="true"/>
     <npc name="Bob" hasDialog="true" position="50.0,100.0"/>
index 1282e4c85533fbf3b4456d10c490621108658d36..77ccf513b145e2e3b0811cb024ad623510805839 100644 (file)
@@ -3,5 +3,5 @@
     <style background="0" bgm="assets/music/embark.wav" folder="assets/style/classic/"/>
     <generation width="600"/>
     <time>6000</time>
-    <link left="!town.xml" />
+    <link left="!town.xml"/>
 </World>
index 79f8a4708a2fd9f0033768f7322346dbc2e95a3a..c9c08b900a36b43c603156159e82e2b3e5a26015 100644 (file)
@@ -1,12 +1,11 @@
 <?xml version="1.0"?>
-
 <include file="entities.xml"/>
 
 <IndoorWorld>
     <style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
-    <house width="800" texture="assets/style/classic/bg/insideWoodHouse.png" />
+    <house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>
     <generation width="1600"/>
-       <time>6000</time>
+    <time>6000</time>
     <!--<link outside="town.xml"/>-->
     <npc name="Bob" hasDialog="false" spawnx="30"/>
 </IndoorWorld>