From a45daeda3633bdf25267a0186b39618269dca970 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Mon, 4 Apr 2016 07:32:15 -0400 Subject: XML folder changing --- Makefile | 1 + config/items.xml | 12 +++++++----- include/common.hpp | 7 +++++-- include/inventory.hpp | 1 + main.cpp | 6 +++++- src/common.cpp | 8 ++++++++ src/config.cpp | 6 ++++++ src/entities.cpp | 4 ++-- src/gameplay.cpp | 16 ++++++++++++---- src/inventory.cpp | 22 +++++++++++++++------- src/world.cpp | 20 ++++++++++++++++---- xml/playerSpawnHill1.xml | 9 +++++++++ 12 files changed, 87 insertions(+), 25 deletions(-) diff --git a/Makefile b/Makefile index c8b09e3..6abc13f 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,7 @@ clean: cleandata: rm -rf xml/*.dat + rm -rf storyXML/*.dat $(EXEC): $(CXXOUTDIR)/$(CXXOBJ) main.cpp @echo " CXX/LD main" diff --git a/config/items.xml b/config/items.xml index b3a10a5..abf522c 100644 --- a/config/items.xml +++ b/config/items.xml @@ -4,11 +4,13 @@ - - - - - + + + + + + + diff --git a/include/common.hpp b/include/common.hpp index 5159c88..2abd9db 100644 --- a/include/common.hpp +++ b/include/common.hpp @@ -35,6 +35,8 @@ typedef unsigned int uint; #undef near #endif +//#define SEGFAULT + /** * This flag lets the compiler know that we want to use shaders. */ @@ -157,6 +159,8 @@ extern float VOLUME_SFX; #define initRand(s) srand(s) + + /** * A 'wrapper' for libc's rand(), as we hope to eventually have our own random number * generator. @@ -176,8 +180,7 @@ extern float VOLUME_SFX; */ #define DEBUG_printf( message, ...) DEBUG_prints(__FILE__, __LINE__, message, __VA_ARGS__ ) -#define C(x) std::cout << x << std::endl; - +void C(std::string m); /** * Defines pi for calculations that need it. */ diff --git a/include/inventory.hpp b/include/inventory.hpp index 5336cee..e38f89a 100644 --- a/include/inventory.hpp +++ b/include/inventory.hpp @@ -15,6 +15,7 @@ public: float width; float height; int maxStackSize; + float attribValue; std::string texloc; Texturec *tex; diff --git a/main.cpp b/main.cpp index 951304f..95d4e05 100644 --- a/main.cpp +++ b/main.cpp @@ -154,6 +154,8 @@ Menu *currentMenu; Menu optionsMenu; Menu pauseMenu; +std::string xmlFolder; + extern WorldWeather weather; extern int fadeIntensity; // ui.cpp @@ -227,7 +229,7 @@ int main(int argc, char *argv[]){ * textures for the entities and stuff. */ - if(!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG)){ + if(!(IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) | !(IMG_Init(IMG_INIT_JPG) & IMG_INIT_JPG)){ std::cout << "Could not init image libraries! Error: " << IMG_GetError() << std::endl; return -1; } @@ -389,7 +391,9 @@ int main(int argc, char *argv[]){ fadeIntensity = 250; + std::cout << "emem" << std::endl; initEverything(); + std::cout << "meme" << std::endl; if(!currentWorld){ std::cout<<"currentWorld == NULL!"<Attribute("start"); + if(xmlFolder=="\0")xmlFolder = "xml/"; + std::cout << "Folder: " << xmlFolder << std::endl; + ui::initFonts(); ui::setFontFace(xml.FirstChildElement("font")->Attribute("path")); config::update(); diff --git a/src/entities.cpp b/src/entities.cpp index 6476755..f4e2dd7 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -102,7 +102,7 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o Player::Player(){ //sets all of the player specific traits on object creation width = HLINE * 10; - height = HLINE * 15; + height = HLINE * 16; type = PLAYERT; //set type to player subtype = 0; @@ -697,7 +697,7 @@ void Player::save(void){ void Player::sspawn(float x,float y){ unsigned int i; uint count; - std::ifstream in ("xml/main.dat",std::ios::in | std::ios::binary); + std::ifstream in ("storyXML/main.dat",std::ios::in | std::ios::binary); spawn(x,y); if(in.good()){ diff --git a/src/gameplay.cpp b/src/gameplay.cpp index f398ca0..4aa751f 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -13,6 +13,8 @@ extern Menu *currentMenu; extern Menu pauseMenu; extern Menu optionsMenu; +extern std::string xmlFolder; + extern void mainLoop(void); // main.cpp extern std::vector AIpreaddr; // entities.cpp @@ -209,8 +211,7 @@ CONT: return 0; } -void commonPageFunc( Mob *callee ) -{ +void commonPageFunc( Mob *callee ){ static bool lock = false; if ( !lock ) { @@ -272,16 +273,21 @@ void initEverything(void){ * Read the XML directory into an array. */ - if(getdir("./xml/",xmlFiles)){ + C("Scanning XML directory"); + if(getdir(std::string("./"+xmlFolder).c_str(),xmlFiles)){ std::cout<<"Error reading XML files!!!1"< itemMap; @@ -25,9 +25,12 @@ void items(void){ while(exml){ itemMap.push_back(new Item()); + itemMap.back()->width = exml->FloatAttribute("width") * HLINE; itemMap.back()->height = exml->FloatAttribute("height") * HLINE; itemMap.back()->maxStackSize = exml->UnsignedAttribute("maxstack"); + itemMap.back()->attribValue = exml->FloatAttribute("value"); + itemMap.back()->name = exml->Attribute("name"); itemMap.back()->type = exml->Attribute("type"); @@ -188,6 +191,7 @@ void Inventory::setSelectionDown(){ } void Inventory::draw(void){ + C("Inventory Start Draw"); static unsigned int lop = 0; static std::vectordfp(numSlot); static std::vectoriray(numSlot); @@ -211,6 +215,7 @@ void Inventory::draw(void){ unsigned int a = 0; static bool end = false; static vec2 mouseStart = {0,0}; + C("End define"); for(auto &r : iray){ r.start.x = player->loc.x + (player->width/2); @@ -302,6 +307,7 @@ void Inventory::draw(void){ * a = 0 */ + C("Start drawing inventory"); if(invOpen){ for(auto &mr : massRay){ @@ -427,6 +433,7 @@ void Inventory::draw(void){ } a++; } + C("Done drawing standard inv"); }else if(invHover){ static unsigned int highlight = 0; static unsigned int thing = 0; @@ -545,6 +552,10 @@ void itemDraw(Player *p,uint id){ } } }else hangle = 0.0f; + if(p->inv->usingi){ + p->inv->useItem(); + std::cout << "using" << std::endl; + } glUseProgram(shaderProgram); glUniform1i(glGetUniformLocation(shaderProgram, "sampler"), 0); @@ -586,6 +597,9 @@ int Inventory::useItem(void){ swing=true; Mix_PlayChannel(2,swordSwing,0); } + }else if(itemMap[items[sel].id]->type == "Cooked Food"){ + player->health += itemMap[items[sel].id]->attribValue; + usingi = false; } } return 0; @@ -606,12 +620,6 @@ bool Inventory::detectCollision(vec2 one, vec2 two){ xc += float(i) * cos((hangle+90)*PI/180); yc += float(i) * sin((hangle+90)*PI/180); - /*glColor4f(1.0f,1.0f,1.0f,1.0f); - glBegin(GL_LINES); - glVertex2f(player->loc.x,player->loc.y+player->height/3); - glVertex2f(xc,yc); - glEnd();*/ - if(xc >= one.x && xc <= two.x){ if(yc >= one.y && yc <= two.y){ return true; diff --git a/src/world.cpp b/src/world.cpp index f03606f..8a46e8d 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -37,6 +37,8 @@ extern bool inBattle; extern unsigned int tickCount; // main.cpp +extern std::string xmlFolder; + int worldShade = 0; std::string currentXML; @@ -1086,7 +1088,7 @@ goInsideStructure( Player *p ) if ( b->inside.empty() ) return this; - inside.push_back(currentXML.c_str() + 4); + inside.push_back(currentXML.c_str() + xmlFolder.size()); tmp = loadWorldFromXML( b->inside ); @@ -1098,7 +1100,7 @@ goInsideStructure( Player *p ) } } } else { - current = currentXML.c_str() + 4; + current = currentXML.c_str() + xmlFolder.size(); tmp = loadWorldFromXML( inside.back() ); for ( auto &b : tmp->build ) { if ( current == b->inside ) { @@ -1191,7 +1193,9 @@ void World::load(void){ std::string save,data,line; const char *filedata; - save = (std::string)currentXML + ".dat"; + //std::cout << "Loading from: " << std::string(currentXML + ".dat") << std::endl; + save = std::string(currentXML + ".dat"); + //std::cout << "save file: " << save << std::endl; filedata = readFile(save.c_str()); data = filedata; std::istringstream iss (data); @@ -1453,8 +1457,12 @@ static bool loadedLeft = false; static bool loadedRight = false; World *loadWorldFromXML(std::string path){ + C("Scanning for save file"); + std::cout << "Scanning: " << path << std::endl; if ( !currentXML.empty() ) currentWorld->save(); + std::cout << "After Scanning: " << path << std::endl; + C("Done scanning for save file"); return loadWorldFromXMLNoSave(path); } @@ -1496,7 +1504,9 @@ loadWorldFromXMLNoSave( std::string path ) { if ( path.empty() ) return NULL; - currentXML = (std::string)"xml/" + path; + std::cout << "File path: " << path << std::endl; + currentXML = std::string("storyXML/" + path); + std::cout << "Full file path: " << currentXML << std::endl; xml.LoadFile(currentXML.c_str()); wxml = xml.FirstChildElement("World"); @@ -1678,6 +1688,8 @@ loadWorldFromXMLNoSave( std::string path ) { tmp->load(); } + std::cout << "adadadadasdsa" << std::endl; + return tmp; } diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index a67a932..4930f68 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -13,6 +13,7 @@ + @@ -67,3 +68,11 @@ And it wasn't stormy. Broooooooooooooo... + + + + Here have this sword! + + + + -- cgit v1.2.3