]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
goodbye indoorworld
authorClyne Sullivan <tullivan99@gmail.com>
Tue, 26 Feb 2019 00:03:28 +0000 (19:03 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Tue, 26 Feb 2019 00:03:28 +0000 (19:03 -0500)
assets/bobground.png [new file with mode: 0644]
include/world.hpp
src/world.cpp
xml/!town.xml
xml/bobshouse.xml

diff --git a/assets/bobground.png b/assets/bobground.png
new file mode 100644 (file)
index 0000000..971a69b
Binary files /dev/null and b/assets/bobground.png differ
index d53a40b378fe99fe7091796d66e7fd52d7bc155f..12e694cd80c1a1e1ecb7ea6256f46f990411bbea 100644 (file)
@@ -20,18 +20,6 @@ using namespace tinyxml2;
 #include <thread.hpp>
 #include <vector2.hpp>
 
-/**
- * The line structure.
- * This structure is used to store the world's ground, stored in vertical
- * lines. Dirt color and grass properties are also kept track of here.
- */
-struct WorldData {
-    bool          grassUnpressed; /**< squishes grass if false */
-    float         grassHeight[2]; /**< height of the two grass blades */
-    float         groundHeight;   /**< height of the 'line' */
-    unsigned char groundColor;    /**< a value that affects the ground's color */
-};
-
 /**
  * Defines how many game ticks it takes to go from day to night or vice versa.
  * Technically a half day cycle...
@@ -45,41 +33,19 @@ constexpr const unsigned int DAY_CYCLE = 10000;
  */
 constexpr const float GRAVITY_CONSTANT = 0.001f;
 
-/**
- * Defines the thickness of the floor in an indoor world.
- */
-constexpr const unsigned int INDOOR_FLOOR_THICKNESS = 50;
-
-/**
- * Defines how far each floor can be from the next (height).
- */
-constexpr const unsigned int INDOOR_FLOOR_HEIGHTT = 400;
-
-/**
- * Gets a combined height of the floor and the area before it.
- * This value is commonly used for operations like moving between floors.
- */
-constexpr const unsigned int INDOOR_FLOOR_HEIGHT = (INDOOR_FLOOR_HEIGHTT + INDOOR_FLOOR_THICKNESS);
-
 /**
  * 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 {
-
+struct WorldData {
        // Data variables
        ObjectTexture ground;
        float startX;                /**< The furthest left coordinate of the world. */
 
-       // Indoor variables
-       bool indoor;                 /**< Set to true if this is an indoor world. */
-       Texture indoorTex;           /**< The house's inside texture. */
-       std::string outdoor;         /**< The file name of the outdoor world. */
-       vec2 outdoorCoords;          /**< The coordinates the player should spawn to when exiting. */
-
        // World linkage
        std::string toLeft, toRight; /**< File names of the worlds adjacent to this one. */
+       std::string outdoor;         /**< The file name of the outdoor world. */
 
        // Style variables
        std::string styleFolder;          /**< The folder to get stylized textures from. */
@@ -98,7 +64,7 @@ private:
        /**
         * The world's data.
         */
-       static WorldData2 world;
+       static WorldData world;
 
        /**
         * SDL's object for handling the background music.
index a6083848ed6474005ecebf1e152f89944f15caa3..bb614d3cfbe9f628f076f2c96e9a1e04a74a79de 100644 (file)
@@ -29,7 +29,7 @@ using namespace tinyxml2;
 #include <weather.hpp>
 #include <systems/lua.hpp>
 
-WorldData2        WorldSystem::world;
+WorldData         WorldSystem::world;
 Mix_Music*        WorldSystem::bgmObj;
 std::string       WorldSystem::bgmCurrent;
 TextureIterator   WorldSystem::bgTex;
@@ -83,9 +83,6 @@ float WorldSystem::isAboveGround(const vec2& p)
 
 bool WorldSystem::save(void)
 {      
-       if (world.indoor)
-               return false;
-
        std::ofstream save (game::config::xmlFolder + currentXMLFile + ".dat");
 
        // signature?
@@ -190,19 +187,11 @@ void WorldSystem::loader(void)
        auto wxml = xmlDoc.FirstChildElement("World");
        if (wxml != nullptr) {
                wxml = wxml->FirstChildElement();
-               world.indoor = false;
        } else {
-               wxml = xmlDoc.FirstChildElement("IndoorWorld");
-               UserAssert(wxml != nullptr, "XML Error: Cannot find a <World> or <IndoorWorld> tag in " + xmlPath);
-               wxml = wxml->FirstChildElement();
-               world.indoor = true;
-               if (world.outdoor.empty()) {
-                       world.outdoor = currentXMLFile;
-                       world.outdoorCoords = vec2(0, 100);
-               }
+               UserAssert(0, "XML Error: Cannot find a <World> or <IndoorWorld> tag in " + xmlPath);
        }
 
-       world.toLeft = world.toRight = "";
+       world.toLeft = world.toRight = world.outdoor = "";
        currentXMLFile = toLoad;
 
        //game::entities.reset();
@@ -239,20 +228,8 @@ void WorldSystem::loader(void)
                }
 
                // world generation
-               else if (tagName == "generation") {
-                       generate(wxml->GetText());
-               }
-
-               // indoor stuff
-               else if (tagName == "house") {
-                       if (!world.indoor)
-                               UserError("<house> can only be used inside <IndoorWorld>");
-
-                       //world.indoorWidth = wxml->FloatAttribute("width");
-                       world.indoorTex = Texture(wxml->StrAttribute("texture")); // TODO winbloze lol
-                       auto str = wxml->StrAttribute("texture");
-                       auto tex = Texture(str);
-                       world.indoorTex = tex;
+               else if (tagName == "ground") {
+                       generate(wxml->Attribute("path"));
                }
 
                // weather tag
@@ -262,16 +239,14 @@ void WorldSystem::loader(void)
 
                // link tags
                else if (tagName == "link") {
-                       auto linkTo = wxml->Attribute("left");
-                       if (linkTo != nullptr) {
+                       if (auto linkTo = wxml->Attribute("left"); linkTo != nullptr)
                                world.toLeft = linkTo;
-                       } else {
-                               linkTo = wxml->Attribute("right");
-                               if (linkTo != nullptr)
-                                       world.toRight = linkTo;
-                               else
-                                       UserError("<link> doesn't handle left or right... huh");
-                       }
+                       else if (auto linkTo = wxml->Attribute("right"); linkTo != nullptr)
+                               world.toRight = linkTo;
+                       else if (auto linkTo = wxml->Attribute("outside"); linkTo != nullptr)
+                               world.outdoor = linkTo;
+                       else
+                               UserError("<link> tag with bad attribute");
                }
 
                // time setting
@@ -539,15 +514,8 @@ void WorldSystem::render(void)
                delete[] bgItems;
        }
 
-       vec2 dim;
-       if (world.indoor) {
-               world.indoorTex.use();
-               dim = world.indoorTex.getDim();
-       } else {
-               world.ground.use();
-               dim = world.ground.getDim();
-       }
-
+       world.ground.use();
+       auto dim = world.ground.getDim();
        GLfloat verts[] = {
                world.startX,         0,         z, 0, 0,
                world.startX + dim.x, 0,         z, 1, 0,
@@ -698,18 +666,15 @@ void WorldSystem::goWorldPortal(Position& p)
 {
        std::string file;
 
-       if (world.indoor) {
+       if (!world.outdoor.empty()) {
                file = world.outdoor;
-               p.x = world.outdoorCoords.x; // ineffective, player is regen'd
-               p.y = world.outdoorCoords.y;
+               world.outdoor = "";
        } 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;
                        }
                });
index 1b1d52785572ace3af59ae08e0c17aaf14471193..545fddf940f223b0371d301aa071f73386ea625d 100644 (file)
@@ -12,7 +12,7 @@
                <layer path="bg/dirt.png"/>
                <layer path="bg/grass.png"/>
        </style>
-       <generation>assets/testground.png</generation>
+       <ground path="assets/testground.png"/>
        <weather>Sunny</weather>
        <link right="!town2.xml"/>
        <spawnx>-300</spawnx>
index 384af4facfe85cc3a79584aa4e31bff21311751a..a699b19e7e6a5ce29a6fd48918619916c04e702c 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0"?>
 <include file="entities.xml"/>
 
-<IndoorWorld>
+<World>
        <style bgm="assets/music/theme_jazz.wav" folder="assets/style/indoors/">
                <layer path="bg/bg.png"/>
                <layer path="bg/bgFarMountain.png"/>
                <layer path="bg/dirt.png"/>
                <layer path="bg/carpet.png"/>
        </style>
-       <house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>
-       <generation>testground.png</generation>
+       <!--<house width="800" texture="assets/style/classic/bg/insideWoodHouse.png"/>-->
+       <ground path="assets/bobground.png"/>
        <time>6000</time>
-       <!--<link outside="town.xml"/>-->
+       <link outside="!town.xml"/>
        <npc name="Bob" hasDialog="true" spawnx="30"/>
-</IndoorWorld>
+</World>
 
 <Dialog name="Bob">
        <text id="0" nextid="1">