]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
XML folder changing
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 4 Apr 2016 11:32:15 +0000 (07:32 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 4 Apr 2016 11:32:15 +0000 (07:32 -0400)
12 files changed:
Makefile
config/items.xml
include/common.hpp
include/inventory.hpp
main.cpp
src/common.cpp
src/config.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/world.cpp
xml/playerSpawnHill1.xml

index c8b09e3d4615905bf37ad0289918a607b0205950..6abc13f259fa27544c2b328dc11ee849635eb130 100644 (file)
--- 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"
index b3a10a554ca1334f0f9f110e9ba95e7ec7b40a31..abf522c27ce2e4edc9d3ebde158e35b4446edb69 100644 (file)
@@ -4,11 +4,13 @@
 <currency name="George Washington" value="25" sprite="assets/items/coin2.png"/>
 <currency name="Barack Hussein Obama" value="100" sprite="assets/items/coin3.png"/>
 
-<item name="Debug"       type="Tool"  maxStackSize="1"   width="1"  height="1"  sprite="assets/items/ITEM_TEST.png" />
-<item name="Dank MayMay" type="Tool"  maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" />
-<item name="Your Bag"    type="Equip" maxStackSize="1"   width="5"  height="5"  sprite="assets/items/ITEM_TEST.png" />
-<item name="Flashlight"  type="Tool"  maxStackSize="1"   width="4"  height="8"  sprite="assets/items/flashlight_off.png" />
-<item name="Wood Sword"  type="Sword"  damage="69" maxStackSize="1"   width="4"  height="10" sprite="assets/items/SWORD_WOOD.png" />
+<item name="Debug"          type="Tool"         value="10" maxStackSize="1"   width="1"  height="1"  sprite="assets/items/ITEM_TEST.png" />
+<item name="Dank MayMay"    type="Tool"         value="10" maxStackSize="420" width="10" height="10" sprite="assets/items/ITEM_TEST.png" />
+<item name="Your Bag"       type="Equip"        value="32" maxStackSize="1"   width="5"  height="5"  sprite="assets/items/ITEM_TEST.png" />
+<item name="Flashlight"     type="Tool"         value="1"  maxStackSize="1"   width="4"  height="8"  sprite="assets/items/flashlight_off.png" />
+<item name="Wood Sword"     type="Sword"        value="69" maxStackSize="1"   width="4"  height="10" sprite="assets/items/SWORD_WOOD.png" />
+<item name="Fried Chicken"  type="Cooked Food"  value="10" maxStackSize="6"   width="4"  height="6"  sprite="assets/items/FOOD_CHICKEN_FRIED.png" />
+
 <item name="Wood Sword2"  type="Sword" maxStackSize="1"   width="4"  height="10" sprite="assets/items/SWORD_WOOD.png" />
 <item name="Wood Sword3"  type="Sword" maxStackSize="1"   width="4"  height="10" sprite="assets/items/SWORD_WOOD.png" />
 <item name="Wood Sword4"  type="Sword" maxStackSize="1"   width="4"  height="10" sprite="assets/items/SWORD_WOOD.png" />
index 5159c88738cfb87bcaed1e7397d7a179e74e4f27..2abd9db3e596b304b8f4e2626da5f34ffd905250 100644 (file)
@@ -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.
  */
index 5336cee6b7e08d4ec7011b5026e1c3221b080464..e38f89aad3a753005ff4bd337dccddd7addc5dd9 100644 (file)
@@ -15,6 +15,7 @@ public:
        float width;
        float height;
        int   maxStackSize;
+       float attribValue;
 
        std::string texloc;
        Texturec *tex;
index 951304f1d7b60dec1d1ec349c6acc63120bac5fe..95d4e05bbdc173210da465b28e571f666cdb3bec 100644 (file)
--- 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!"<<std::endl;
index 10ff64e4f0f40cf09726bbf3c35be1a8389d64e5..50678f1e59321507352f6aa676c0db7689e51d56 100644 (file)
@@ -20,6 +20,14 @@ unsigned int millis(void){
 
 #endif // __WIN32__
 
+void C(std::string m){
+       #ifdef SEGFAULT
+               std::cout << m << std::endl;
+       #else
+               (void)m;
+       #endif
+}
+
 void DEBUG_prints(const char* file, int line, const char *s,...){
        va_list args;
        printf("%s:%d: ",file,line);
index 4f4ad8939db2913aef896249707ffe9566b9a1d8..2ee13d45ab1beb543638b3425cf5672d7a0069b9 100644 (file)
@@ -13,6 +13,8 @@ extern float VOLUME_MASTER;
 extern float VOLUME_MUSIC;
 extern float VOLUME_SFX;
 
+extern std::string xmlFolder;
+
 XMLDocument xml;
 XMLElement *scr;
 XMLElement *vol;
@@ -52,6 +54,10 @@ namespace config {
                        VOLUME_SFX = fval;
                else VOLUME_SFX = 50;
 
+               xmlFolder = xml.FirstChildElement("world")->Attribute("start");
+               if(xmlFolder=="\0")xmlFolder = "xml/";
+               std::cout << "Folder: " << xmlFolder << std::endl;
+
                ui::initFonts();
                ui::setFontFace(xml.FirstChildElement("font")->Attribute("path"));
                config::update();
index 64767551c0ab75f5debca6fbe8f52243c6597778..f4e2dd7a085009bf0178e5eef3cbeb0a41be2835 100644 (file)
@@ -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()){
index f398ca040fb080b2d85a5fdd476d72ee8218b008..4aa751f6ac009c021c7eb2c49788f4a2d902a572 100644 (file)
@@ -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<NPC *> 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"<<std::endl;
                abort();
        }
+       C("Done scanning XML directory");
 
        /*
         * Sort the files alphabetically.
         */
 
+       C("Sorting XML files alphabetically");
        strVectorSortAlpha(&xmlFiles);
+       C("Dpne sorting XML files alphabetically");
+
 
        /*
         * Load the first file found as currentWorld.
@@ -293,8 +299,10 @@ void initEverything(void){
                        /*
                         * Read in the XML file.
                         */
-
+                       C("Setting current XML file");
+                       std::cout << "File to load: " << xmlFiles[i] << std::endl;
                        currentWorld = loadWorldFromXML(xmlFiles[i]);
+                       C("Done setting current XML file");
                        break;
                }
        }
index a2723fb85c0adbe9ab34cf5e8e2ed0dfd6de4e5f..474a9411ed2fad80bfe422a813d180b7586c7de3 100644 (file)
@@ -10,7 +10,7 @@ extern GLuint invUI;
 static float hangle = 0.0f;
 static bool swing = false;
 static vec2 itemLoc;
-static const unsigned int numSlot = 2000;
+static const unsigned char numSlot = 7;
 Mix_Chunk* swordSwing;
 
 static std::vector<Item *> 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::vector<int>dfp(numSlot);
        static std::vector<Ray>iray(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;
index f03606f75d80317d3f56b14fdae58b7696e7fe87..8a46e8d77ccdc30ecee1dcaf9dad64f079399e5c 100644 (file)
@@ -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;
 
 }
index a67a932893580d4c5512c31b3d8b950fd3fc347f..4930f688465f2a1b6a0facee064162755425bb2c 100644 (file)
@@ -13,6 +13,7 @@
 
        <npc name="Ralph" hasDialog="true" />
        <npc name="Johnny" hasDialog="false" />
+       <npc name="Big Dave" hasDialog="true"/>
 
        <page x="-200" id="assets/pages/gootaGoFast.png" />
 
@@ -67,3 +68,11 @@ And it wasn't stormy.
                Broooooooooooooo...
        </text>
 </Dialog>
+
+<Dialog name="Big Dave">
+       <text id="0" pause="true">
+               Here have this sword!
+               <give id="Wood Sword" count="1"/>
+               <give id="Fried Chicken" count="1"/>
+       </text>
+</Dialog>