From 8f385ec7ac5a78bc3bf70170f4ab39ebcac8e32a Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 15 Jun 2016 07:40:52 -0400 Subject: world saving / new game script stuff --- Changelog | 9 +++++ assets/music/africa.mp3 | Bin 0 -> 4394736 bytes brice.dat | 6 ++-- include/entities.hpp | 2 +- include/world.hpp | 4 +-- main.cpp | 3 +- src/entities.cpp | 37 +++++++++++++++++-- src/world.cpp | 39 ++++++++++---------- xml/000.xml | 19 ++++++---- xml/001.xml | 7 ++++ xml/playerSpawnHill1.xml | 72 +++++++------------------------------ xml/playerSpawnHill1_Building1.xml | 6 ++-- 12 files changed, 106 insertions(+), 98 deletions(-) create mode 100644 assets/music/africa.mp3 create mode 100644 xml/001.xml diff --git a/Changelog b/Changelog index 9cbe995..0f6c748 100644 --- a/Changelog +++ b/Changelog @@ -1043,3 +1043,12 @@ - game is overall better - following lights, good lights - good + +6/13/2016: +========== + + - more actual finally story work + - laughed at Goals.txt + - worked on better inventory / general ui + + ~ more than 10800 lines of code (just counting .hpp's and .cpp's) diff --git a/assets/music/africa.mp3 b/assets/music/africa.mp3 new file mode 100644 index 0000000..c6073d5 Binary files /dev/null and b/assets/music/africa.mp3 differ diff --git a/brice.dat b/brice.dat index 3b090ad..ee48d24 100644 --- a/brice.dat +++ b/brice.dat @@ -1,7 +1,7 @@ 3 -canSprint +Slow 0 canJump 0 -Slow -1 +canSprint +0 diff --git a/include/entities.hpp b/include/entities.hpp index 605cc77..7e68be3 100644 --- a/include/entities.hpp +++ b/include/entities.hpp @@ -160,7 +160,7 @@ public: bool near; // when true, the entity can move - bool canMove; + int canMove; // tells direction entity is facing bool right, left; diff --git a/include/world.hpp b/include/world.hpp index e240973..cea79c1 100644 --- a/include/world.hpp +++ b/include/world.hpp @@ -397,8 +397,8 @@ public: */ std::string getSTextureLocation(unsigned int index) const; - // saves the world's data to an XML file - void save(void); + // saves the world's data to an XML file, either the one provided or the current path + void save(const std::string& s=""); // plays/pauses the world's music, according to if a new world is being entered void bgmPlay(World *prev) const; diff --git a/main.cpp b/main.cpp index 9c0ba2f..52841c6 100644 --- a/main.cpp +++ b/main.cpp @@ -33,7 +33,7 @@ constexpr const char *GAME_NAME = "Independent Study v0.8 alpha - NOW WITH decen SDL_Window *window = NULL; // main loop runs based on this variable's value -bool gameRunning = false; +bool gameRunning = true; // world objects for the current world and the two that are adjacent World *currentWorld = NULL, @@ -325,7 +325,6 @@ int main(int argc, char *argv[]) arena->setBGM("assets/music/embark.wav"); // the main loop, in all of its gloriousness.. - gameRunning = true; std::thread([&]{ while (gameRunning) { mainLoop(); diff --git a/src/entities.cpp b/src/entities.cpp index 9f9a47c..90e03eb 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -7,6 +7,7 @@ #include #include #include +#include extern std::istream *names; @@ -638,6 +639,8 @@ void NPC::interact() { //have the npc's interact back to the player std::string nname; unsigned int idx; bool stop; + float tgt = 0.12345678f; + bool pmove = true, advance = false; loc.y += 5; @@ -707,8 +710,20 @@ COMMONAIFUNC: } // handle movement directs - if ((oxml = exml->FirstChildElement("gotox"))) - moveTo(std::stoi(oxml->GetText())); + if ((oxml = exml->FirstChildElement("gotox"))) { + moveTo((tgt = std::stoi(oxml->GetText()))); + if (oxml->QueryBoolAttribute("playerMove", &pmove) != XML_NO_ERROR) + pmove = true; + if (oxml->QueryBoolAttribute("advance", &advance) != XML_NO_ERROR) + advance = false; + } + + // handle attribute setting + if ((oxml = exml->FirstChildElement("set"))) { + do game::setValue(oxml->StrAttribute("id"), oxml->StrAttribute("value")); + while ((oxml = oxml->NextSiblingElement())); + game::briceUpdate(); + } // asdlfkj if (exml->GetText() == nullptr) @@ -760,6 +775,20 @@ OTHERSTUFF: } } + if (tgt != 0.12345678f) { + stop = canMove; + canMove = true; + while (targetx != 0.9112001f) { + if (!pmove) + player->speed = 0; + } + if (!pmove) { + pmove = true; + player->speed = 1; + } + canMove = stop; + } + // handle potential following dialogs if ((idx = exml->UnsignedAttribute("nextid"))) { dialogIndex = idx; @@ -781,6 +810,10 @@ OTHERSTUFF: } } + // advance if desired + if (advance) + goto COMMONAIFUNC; + // stop talking else { // error text? diff --git a/src/world.cpp b/src/world.cpp index 2eebc4a..450d956 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -797,7 +797,7 @@ void World::draw(Player *p) pc += 30; if (pc > pss) { // TODO resize the vector or something better than breaking - std::cout << "Whoops:" << pc << "," << partVec.size() << std::endl; + //std::cout << "Whoops:" << pc << "," << partVec.size() << std::endl; break; } particles[i].draw(pIndex); @@ -1150,12 +1150,11 @@ getStructurePos(int index) /** * Saves world data to a file. */ -void World::save(void) +void World::save(const std::string& s) { for (const auto &e : entity) e->saveToXML(); - - currentXMLDoc.SaveFile(currentXML.c_str(), false); + currentXMLDoc.SaveFile((xmlFolder + (s.empty() ? currentXML : s)).c_str(), false); } /** @@ -1285,7 +1284,6 @@ std::string World::getToRight(void) const WorldSwitchInfo World::goWorldLeft(Player *p) { World *tmp; - // check if player is at world edge if (!toLeft.empty() && p->loc.x < worldStart + HLINES(15)) { // load world (`toLeft` conditional confirms existance) @@ -1305,7 +1303,6 @@ WorldSwitchInfo World::goWorldLeft(Player *p) WorldSwitchInfo World::goWorldRight(Player *p) { World *tmp; - if (!toRight.empty() && p->loc.x + p->width > -worldStart - HLINES(15)) { tmp = loadWorldFromPtr(currentWorldToRight); return std::make_pair(tmp, vec2 {tmp->worldStart + (float)HLINES(15.0), GROUND_HEIGHT_MINIMUM} ); @@ -1851,24 +1848,28 @@ static bool loadedRight = false; World *loadWorldFromXML(std::string path) { if (!currentXML.empty()) - currentWorld->save(); + currentWorld->save(path); return loadWorldFromXMLNoSave(path); } World *loadWorldFromPtr(World *ptr) { - World *tmp = ptr; - - loadedLeft = true; - currentWorldToLeft = loadWorldFromXML(tmp->getToLeft()); - loadedLeft = false; - - loadedRight = true; - currentWorldToRight = loadWorldFromXML(tmp->getToRight()); - loadedRight = false; + currentWorld->save(); // save the current world to the current xml path + + if (ptr->getToLeft() == currentXML) { + currentWorldToLeft = currentWorld; + loadedRight = true; + currentWorldToRight = loadWorldFromXMLNoSave(ptr->getToRight()); + loadedRight = false; + } else if (ptr->getToRight() == currentXML) { + currentWorldToRight = currentWorld; + loadedLeft = true; + currentWorldToLeft = loadWorldFromXMLNoSave(ptr->getToLeft()); + loadedLeft = false; + } - return tmp; + return ptr; } /** @@ -2009,7 +2010,7 @@ loadWorldFromXMLNoSave(std::string path) { } // set spawn x for player - else if (name == "spawnx") { + else if (name == "spawnx" && !(loadedLeft | loadedRight)) { player->loc.x = std::stoi(wxml->GetText()); } @@ -2044,7 +2045,7 @@ loadWorldFromXMLNoSave(std::string path) { } // time setting - else if (name == "time") { + else if (name == "time" && !(loadedLeft | loadedRight)) { game::time::setTickCount(std::stoi(wxml->GetText())); } diff --git a/xml/000.xml b/xml/000.xml index 9996cec..bf0af6c 100644 --- a/xml/000.xml +++ b/xml/000.xml @@ -1,20 +1,25 @@