]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
names fix
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 22 Jan 2016 12:41:08 +0000 (07:41 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 22 Jan 2016 12:41:08 +0000 (07:41 -0500)
include/common.h
main.cpp
src/entities.cpp
src/world.cpp

index 4115f104853867fbd604b0001fa66a10429aeaa1..0df6533e99c2a03a926c6fb20e78b8110a1f7f63 100644 (file)
@@ -110,7 +110,7 @@ extern unsigned int SCREEN_HEIGHT;
  * 
  */
 
-#define HLINE 4
+#define HLINE 3
 
 /**
  * A 'wrapper' for libc's srand(), as we hope to eventually have our own random number
index c8ff1785a8cd7c2a25d1cabfab8657e1e6c0b2f8..cfcf7ece6c3f63913c1e5aff1ce013d14398bca2 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -123,13 +123,6 @@ GLuint colorIndex;
 
 Mix_Chunk *crickets;
 
-/*
- *     names is used to open a file containing all possible NPC names. It is externally
- *     referenced in src/entities.cpp for getting random names.
-*/
-
-std::istream *names;
-
 /*
  *     loops is used for texture animation. It is believed to be passed to entity
  *     draw functions, although it may be externally referenced instead.
@@ -376,25 +369,14 @@ int main(/*int argc, char *argv[]*/){
        //glEnable(GL_DEPTH_TEST); //THIS DOESN'T WORK ON LINUX
        glEnable(GL_MULTISAMPLE);
 
-       /*
-        *      Open the names file containing potential names for NPCs and store it in the names file
-        *      pointer. This will be reference by getName in src/entities.cpp when NPCs are spawned. 
-        * 
-       */
-       
-       static std::filebuf fb;
-       fb.open("assets/names_en-us",std::ios::in);
-       names = new std::istream(&fb);
-       
-
        crickets=Mix_LoadWAV("assets/sounds/crickets.wav");
        //Mix_Volume(2,25);
        
        /*
         *      Create all the worlds, entities, mobs, and the player. This function is defined in
         *      src/gameplay.cpp
-        * 
-       */
+        */
+        
        fadeIntensity = 250;
        initEverything();
 
@@ -432,8 +414,6 @@ int main(/*int argc, char *argv[]*/){
     Mix_HaltMusic();
     Mix_CloseAudio();
     
-    fb.close();
-    
     destroyInventory();
        ui::destroyFonts();
     Texture::freeTextures();
index 7f7d79870eb28d761290610579ba15124612c089..88ef6b9910b650ba998c072061a135336523c00f 100644 (file)
@@ -32,18 +32,26 @@ void getRandomName(Entity *e){
        unsigned int tempNum,max=0;
        char *bufs;
        
-       names->seekg(0,names->beg);
+       std::ifstream names ("assets/names_en-us",std::ios::in);
+       
+       names.seekg(0,names.beg);
        
        bufs = new char[32];
        
-       for(;!names->eof();max++)
-               names->getline(bufs,32);
+       std::cout<<"1\n";
+       
+       for(;!names.eof();max++)
+               names.getline(bufs,32);
+       
+       std::cout<<"2\n";
        
        tempNum = rand() % max;
-       names->seekg(0,names->beg);
+       names.seekg(0,names.beg);
        
        for(unsigned int i=0;i<tempNum;i++)
-               names->getline(bufs,32);
+               names.getline(bufs,32);
+       
+       names.close();
        
        switch(bufs[0]){
        default :
index 113d98aa2dfab9104557407c07e1000d7d8f24c7..71bd0f4682fe303ae71b64b0ca6d65a751815e35 100644 (file)
@@ -1482,12 +1482,13 @@ World *loadWorldFromXML(const char *path){
                        
                }else if(!strcmp(name,"npc")){
                        const char *npcname;
-                       
+
                        if(wxml->QueryFloatAttribute("x",&spawnx) != XML_NO_ERROR)
                                tmp->addNPC(getRand() % tmp->getTheWidth() / 2.0f,100);
                        else
                                tmp->addNPC(spawnx,wxml->FloatAttribute("y"));
                        
+                       
                        if((npcname = wxml->Attribute("name"))){
                                delete[] tmp->npc.back()->name;
                                tmp->npc.back()->name = new char[strlen(npcname) + 1];