From 8fad6784c4316e1fe41290ae80e6a8c535de4fa1 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 25 Feb 2019 19:03:28 -0500 Subject: goodbye indoorworld --- assets/bobground.png | Bin 0 -> 925 bytes include/world.hpp | 40 +++--------------------------- src/world.cpp | 67 ++++++++++++--------------------------------------- xml/!town.xml | 2 +- xml/bobshouse.xml | 10 ++++---- 5 files changed, 25 insertions(+), 94 deletions(-) create mode 100644 assets/bobground.png diff --git a/assets/bobground.png b/assets/bobground.png new file mode 100644 index 0000000..971a69b Binary files /dev/null and b/assets/bobground.png differ diff --git a/include/world.hpp b/include/world.hpp index d53a40b..12e694c 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -20,18 +20,6 @@ using namespace tinyxml2; #include #include -/** - * 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. diff --git a/src/world.cpp b/src/world.cpp index a608384..bb614d3 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -29,7 +29,7 @@ using namespace tinyxml2; #include #include -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 or 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 or 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(" can only be used inside "); - - //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(" 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(" 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( [&](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; } }); diff --git a/xml/!town.xml b/xml/!town.xml index 1b1d527..545fddf 100644 --- a/xml/!town.xml +++ b/xml/!town.xml @@ -12,7 +12,7 @@ - assets/testground.png + Sunny -300 diff --git a/xml/bobshouse.xml b/xml/bobshouse.xml index 384af4f..a699b19 100644 --- a/xml/bobshouse.xml +++ b/xml/bobshouse.xml @@ -1,7 +1,7 @@ - + - - testground.png + + - + - + -- cgit v1.2.3