]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
indoor world work
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 19 Oct 2016 00:26:12 +0000 (20:26 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 19 Oct 2016 00:26:12 +0000 (20:26 -0400)
include/entities.hpp
include/world.hpp
src/entities.cpp
src/world.cpp
xml/!town.xml
xml/bobshouse.xml

index 49598bdd3b292bfb804c86e01b14a252ae3a1bb0..945e8c839db96737da9da699e8e10c528eaf8b02 100644 (file)
@@ -343,6 +343,8 @@ public:
        std::string inside;
        std::string textureLoc;
 
+       GLuint insideTex;
+
        Structures();
        ~Structures();
 
index 7dccf1b34c27e262924a8898ddef966cfde45ffe..dc07267e39a8c85e262c279d745b46d359bbf04c 100644 (file)
@@ -17,8 +17,7 @@
  * in World::setBackground() to select the appropriate images.
  */
 enum class WorldBGType : unsigned int {
-       Forest = 0,     /**< A forest theme. */
-       WoodHouse       /**< An indoor wooden house theme. */
+       Forest = 0      /**< A forest theme. */
 };
 
 /**
@@ -199,6 +198,7 @@ private:
 public:
 
        float HouseWidth;
+       GLuint houseTex;
 
        inline bool isIndoor(void) const
        { return m_Indoor; }
index 6b9c3fe0b4a4431d8b62a7cc2bccfcd5847c840f..e005df5b04d61e30d76bbf75f59eafd53d2b4c8e 100644 (file)
@@ -163,7 +163,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
                } else if (kc == getControl(4)) {
                        p->speed = .5;
                } else if (kc == getControl(5)) {
-                       static int heyOhLetsGo = 0;
+                       /*static int heyOhLetsGo = 0;
 
                        //edown = true;
 
@@ -179,7 +179,7 @@ void PlayerSystem::receive(const KeyDownEvent &kde)
 
                                // enable action ui
                                ui::action::enable();
-                       }
+                       }*/
                }
        } else if (kc == SDLK_DELETE) {
                game::endGame();
@@ -500,6 +500,8 @@ void Structures::createFromXML(XMLElement *e, World *w)
 
        textureLoc = e->StrAttribute("texture");
 
+       insideTex = Texture::loadTexture(e->StrAttribute("insideTexture"));
+
        spawn(static_cast<BUILD_SUB>(e->UnsignedAttribute("type")),
              e->QueryFloatAttribute("spawnx", &spawnx) == XML_NO_ERROR ? spawnx : (randGet() % w->getTheWidth() / 2.0f),
              100);
index 816b280e5b2b146bf754f30e21a9d0bef50cd031..ef9969f62f57cd8aeda7d4cf6679f7d391fbfe83 100644 (file)
@@ -77,16 +77,20 @@ std::string currentXML;
 static std::vector<WorldSwitchInfo> arenaNest;
 
 // pathnames of images for world themes
-static const std::string bgPaths[] = {
-    "bg.png",                                  // Daytime background
-    "bgn.png",                                 // Nighttime background
-    "bgFarMountain.png",               // Furthest layer
-    "forestTileFar.png",               // Furthest away Tree Layer
-    "forestTileBack.png",              // Closer layer
-    "forestTileMid.png",               // Near layer
-    "forestTileFront.png",             // Closest layer
-    "dirt.png",                                        // Dirt
-    "grass.png",                               // Grass
+using StyleList = std::array<std::string, 9>;
+
+static const std::vector<StyleList> bgPaths = {
+       { // Forest 
+               "bg.png",                               // daytime background
+               "bgn.png",                              // nighttime background
+               "bgFarMountain.png",    // layer 1 (furthest)
+               "forestTileFar.png",    // layer 2
+               "forestTileBack.png",   // layer 3
+               "forestTileMid.png",    // layer 4
+               "forestTileFront.png",  // layer 5 (closest)
+               "dirt.png",                             // ground texture
+               "grass.png"                             // grass (ground-top) texture
+       }
 };
 
 // pathnames of structure textures
@@ -614,6 +618,7 @@ WorldSwitchInfo World::goInsideStructure(Player *p)
                delete[] buf;
 
                tmp = dynamic_cast<Structures *>(*d)->insideWorld;
+               tmp->houseTex = dynamic_cast<Structures *>(*d)->insideTex;
 
                return std::make_pair(tmp, vec2 {0, 100});
        }
@@ -637,7 +642,7 @@ WorldSwitchInfo World::goInsideStructure(Player *p)
         }
 
         if (b == nullptr)*/
-            return std::make_pair(this, vec2 {0, 0});
+            return std::make_pair(currentWorld, vec2 {0, 100});
 
                //return std::make_pair(tmp, vec2 {b->loc.x + (b->width / 2), 0});
        }
@@ -1416,16 +1421,14 @@ void WorldSystem::render(void)
                bg_tex.clear();
 
                if (world->isIndoor() && i == 3) {
-                       static const GLuint tex = Texture::loadTexture(world->styleFolder + "insideWoodHouse.png");
-                       static const auto dimm = Texture::imageDim(world->styleFolder + "insideWoodHouse.png");
-                       glBindTexture(GL_TEXTURE_2D, tex);
+                       glBindTexture(GL_TEXTURE_2D, world->houseTex);
 
                        bg_items.emplace_back(worldStart, GROUND_HEIGHT_MINIMUM, 7-(i*.1));
                bg_items.emplace_back(worldStart + world->HouseWidth, GROUND_HEIGHT_MINIMUM,    7-(i*.1));
-               bg_items.emplace_back(worldStart + world->HouseWidth, GROUND_HEIGHT_MINIMUM + dimm.y, 7-(i*.1));
+               bg_items.emplace_back(worldStart + world->HouseWidth, GROUND_HEIGHT_MINIMUM + dim.y, 7-(i*.1));
 
-               bg_items.emplace_back(worldStart + world->HouseWidth, GROUND_HEIGHT_MINIMUM + dimm.y, 7-(i*.1));
-               bg_items.emplace_back(worldStart, GROUND_HEIGHT_MINIMUM + dimm.y, 7-(i*.1));
+               bg_items.emplace_back(worldStart + world->HouseWidth, GROUND_HEIGHT_MINIMUM + dim.y, 7-(i*.1));
+               bg_items.emplace_back(worldStart, GROUND_HEIGHT_MINIMUM + dim.y, 7-(i*.1));
                bg_items.emplace_back(worldStart, GROUND_HEIGHT_MINIMUM,        7-(i*.1));
                } else {
                        for (int j = worldStart; j <= -worldStart; j += dim.x) {
@@ -1594,10 +1597,10 @@ void WorldSystem::setWorld(World *w)
 
        bgFiles.clear();
 
-       for (int i = 0; i < 9; i++) { 
-               int idx = /*((int)w->bgType * 9) +*/ i;
-               bgFiles.push_back(w->styleFolder + bgPaths[idx]);
-       }
+       const auto& files = bgPaths[(int)w->bgType];
+
+       for (const auto& f : files)
+               bgFiles.push_back(w->styleFolder + f);
 
        bgTex = TextureIterator(bgFiles);
 }
@@ -1639,7 +1642,7 @@ void WorldSystem::enterWorld(World *w)
 
 void WorldSystem::leaveWorld(void)
 {
-       world = outside;
+       world = currentWorld = outside;
 } 
 
 void WorldSystem::singleDetect(Entity *e, entityx::TimeDelta dt)
index 9d0838b80187e7ba68db32143fcaaadc37d8d973..2d110e87ce41cc712ab15c32103c3aa8450cb094 100644 (file)
@@ -4,10 +4,10 @@
     <generation width="1600"/>
     <time>6000</time>
     <spawnx>-300</spawnx>
-    <npc name="Sanc" hasDialog="true" health="1" x="23.971899" y="59.998001" dindex="9999"/>
-    <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="308.18121" y="60.597992" dindex="0"/>
+    <npc name="Sanc" hasDialog="true" health="1" x="-324.26083" y="70.398842" dindex="9999"/>
+    <npc name="Bob" hasDialog="true" spawnx="30" health="1" x="151.69295" y="71.5989" dindex="0"/>
     <structure type="1" spawnx="300" alive="1"/>
-    <structure inside="bobshouse.xml" type="1" spawnx="10" alive="1"/>
+    <structure inside="bobshouse.xml" insideTexture="assets/style/classic/bg/insideWoodHouse.png" type="1" spawnx="10" alive="1"/>
     <chest alive="1"/>
 </World>
 
index 43644ca3b8875602d135e0a37c6620e0c09ee3a4..f13d5ffb5f94c50eeffce9e738142f623d54ab0d 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <IndoorWorld>
-    <style background="1" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
+    <style background="0" bgm="assets/music/theme_jazz.wav" folder="assets/style/classic/"/>
        <house width="800" />
        <generation width="1600" />     
     <link outside="town.xml"/>