]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
enabled werror, wall and wextra (\!)
authorClyne Sullivan <tullivan99@gmail.com>
Thu, 3 Dec 2015 20:50:07 +0000 (15:50 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Thu, 3 Dec 2015 20:50:07 +0000 (15:50 -0500)
13 files changed:
Makefile
include/entities.h
include/inventory.h
include/world.h
main.cpp
src/Makefile
src/Quest.cpp
src/Texture.cpp
src/entities.cpp
src/gameplay.cpp
src/inventory.cpp
src/ui.cpp
src/world.cpp

index 307b137944b5304b16e5c7353407e9ff40f5b4bc..e48afa64b935eb0b3a43a72be0fcc07797b69bde 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ LIBS = -lpthread -lGL -lGLEW -lSDL2 -lfreetype -lSDL2_image -lSDL2_mixer
 \r
 WIN_LIBS = -lopengl32 -lglew32 -lmingw32 -lSDL2main -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype\r
 \r
-FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2\r
+FLAGS = -std=c++11 -Iinclude -Iinclude/freetype2 -Wall -Wextra -Werror\r
 \r
 MFLAGS64 = 64\r
 all:\r
index 19dd492542ae42918f0de0c4b6c0de9f5cf2322f..77ca347b9855d074bde55bdf4bd12875dc6898d8 100644 (file)
@@ -87,6 +87,8 @@ public:
        
        virtual void wander(int){}
        virtual void interact(){}
+       
+       virtual ~Entity(){}
 };
 
 class Player : public Entity {
index 1ad46d0330740bc9543828f18ba2c3c5b1eed968..e71e76a7b72b925e269f1de437855c801ac5cedb 100644 (file)
@@ -48,7 +48,6 @@ public:
        char* textureLoc;
        Texturec *tex;
        GLuint text;
-       int count;
 
        Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const char *tl);
        GLuint rtex(){
index 57ea091d1454a7510b45cdf0f94dfa8b4b9f6db9..952c2e5de4a56eef13e92018da46b034195371bc 100644 (file)
@@ -118,7 +118,7 @@ public:
        */
                                                
        World(void);
-       ~World(void);                           // Frees the 'line' array.
+       virtual ~World(void);                           // Frees the 'line' array.
        
        /*
         *      Generate a world of width `width`. This function is virtual so that other world
@@ -183,6 +183,8 @@ public:
        
        int getTheWidth(void);
        
+       void save(FILE *);
+       void load(FILE *);
 };
 
 /*
index f24b9bdea0c3ed53117d56bcbf853c92d6185233..fb07b387e2f2922439cd6199aabfa7193c281f3d 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -220,7 +220,7 @@ static unsigned int fadeIntensity = 0;
  * MAIN ************************************************************************
  *******************************************************************************/
 
-int main(int argc, char *argv[]){
+int main(/*int argc, char *argv[]*/){
        gameRunning=false;
 
        /*!
@@ -708,7 +708,7 @@ void render(){
                glUniform3f(glGetUniformLocation(shaderProgram, "lightColor"), 1,1,1);
                glUniform1f(glGetUniformLocation(shaderProgram, "lightStrength"), 5);
                glColor4f(1.0f, 1.0f, 1.0f, .5f);
-               for(auto r = 0; r < fray.size(); r++){
+               for(unsigned int r = 0; r < fray.size(); r++){
                        glBegin(GL_TRIANGLES);
                                glVertex2f(fray[r].start.x, fray[r].start.y);
                                glVertex2f(fray[r].end.x, fray[r].end.y);
index 03652fce3b9408c90cad9602af19b579d5e400d5..91743efb2980d8536a1ce5dd35bb7dd3815ce8f1 100644 (file)
@@ -1,6 +1,6 @@
 LIBS = -lpthread -lGL -lSDL2 -lSDL2_image -lSDL2_mixer -lfreetype
 
-FLAGS = -std=c++11 -I../include -I../include/freetype2
+FLAGS = -std=c++11 -I../include -I../include/freetype2 -Wall -Wextra -Werror
 
 OUT = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out\//g'`
 OUT64 = `echo "" $$(ls -c $(wildcard *.cpp)) | sed s/.cpp/.o/g | sed 's/ / ..\/out64\//g'`
index 4e8522ddf985f5fe6abdd3ddc26cef415b473297..0905a8745e2fcf538aa61ffb7ec8a605f6270d5a 100644 (file)
@@ -67,7 +67,6 @@ int QuestHandler::drop(const char *t){
 \r
 int QuestHandler::finish(const char *t,void *completer){\r
        unsigned char i;\r
-       unsigned int r;\r
        for(i=0;i<current.size();i++){\r
                if(!strcmp(current[i]->title,t)){\r
 #ifdef DEBUG\r
index a44f1a7cb2a662a60a5c67ae9847642774ea9999..5e5651d85e3f260069f023107124e61c77959d96 100644 (file)
@@ -66,11 +66,11 @@ namespace Texture{
 }
 
 Texturec::Texturec(uint amt, ...){
+       va_list fNames;
        texState = 0;
        image = new GLuint[amt];
-       va_list fNames;
        va_start(fNames, amt);
-       for(int i = 0; i < amt; i++){
+       for(unsigned int i = 0; i < amt; i++){
                image[i] = Texture::loadTexture(va_arg(fNames, char *));
        }
        va_end(fNames);
@@ -79,7 +79,7 @@ Texturec::Texturec(uint amt, ...){
 Texturec::Texturec(uint amt,const char **paths){
        texState = 0;
        image = new GLuint[amt];
-       for(int i = 0; i < amt; i++){
+       for(unsigned int i = 0; i < amt; i++){
                image[i] = Texture::loadTexture(paths[i]);
        }
 }
index 7f786373163e636d878978222a51690cedea3357..a2bff3cffe69ec33792f8c0e805753604f6a4f46 100644 (file)
@@ -12,7 +12,7 @@ extern const char *itemName;
 
 void getRandomName(Entity *e){
        int tempNum,max=0;
-       char buf,*bufs;
+       char *bufs;
        
        rewind(names);
        
@@ -358,38 +358,35 @@ void Object::interact(void){
  *                                                     void spawn points for large amounts of entities. This would allow for the spawn
  *                                                     point to have non-normal traits so it could be invisible or invincible...
 */
-unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure based off of type and coords
+
+unsigned int Structures::spawn(_TYPE t, float x, float y){
        loc.x = x;
        loc.y = y;
        type = t;
        
        alive = true;
 
-       /*VILLAGE*/
-       switch(type){
-       case STRUCTURET:
-               width =  50 * HLINE;
-               height = 40 * HLINE;
+       width =  50 * HLINE;
+       height = 40 * HLINE;
 
+       /*
+        *      tempN is the amount of entities that will be spawned in the village. Currently the village
+        *      will spawn bewteen 2 and 7 villagers for the starting hut.
+       */
+       
+       unsigned int tempN = (getRand() % 5 + 2);
+       
+       while(--tempN){
+               
                /*
-                *      tempN is the amount of entities that will be spawned in the village. Currently the village
-                *      will spawn bewteen 2 and 7 villagers for the starting hut.
+                *      This is where the entities actually spawn. A new entity is created
+                *      with type NPC.
                */
                
-               unsigned int tempN = (getRand() % 5 + 2);
+               currentWorld->addNPC(loc.x + (tempN - 5),100);
                
-               for(int i=0;i<tempN;i++){
-                       
-                       /*
-                        *      This is where the entities actually spawn. A new entity is created
-                        *      with type NPC by using polymorphism.
-                       */
-                       
-                       currentWorld->addNPC(loc.x+(i-5),100);
-                       
-               }
-               break;
        }
+
        return 0;
 }
 
index c9c2b1eb72923b2ef133d5f565e466cce69d7e86..2854e60f60a88ca3c27bf6e2380622fab970a189 100644 (file)
@@ -13,10 +13,7 @@ int compTestQuest(NPC *speaker){
 }
 
 int giveTestQuest(NPC *speaker){
-       unsigned char i;
-       
        ui::dialogBox(speaker->name,":Yes:No","Here, have a quest!");
-       
        ui::waitForDialog();
        
        if(ui::dialogOptChosen == 1){
@@ -32,20 +29,17 @@ int giveTestQuest(NPC *speaker){
        return 0;
 }
 
-static Arena *a;
-
 void CUTSCENEEE(Mob *callee){
        player->vel.x = 0;
        
        ui::dialogBox(player->name,":K.","No way I\'m gettin\' up this hill.");
        ui::waitForDialog();
 
-       a = new Arena(currentWorld,player);
-       currentWorld = a;
-       
-       /*player->right = true;
+       player->right = true;
        player->left  = false;
-       player->loc.x += HLINE * 5;*/
+       player->loc.x += HLINE * 5;
+       
+       callee->alive = false;
 }
 
 void CUTSCENEEE2(Mob *callee){
@@ -68,7 +62,7 @@ static IndoorWorld *iw;
 void destroyEverything(void);
 
 void initEverything(void){
-       unsigned int i;
+       //FILE *load;
        
        /*
         *      World creation:
@@ -83,9 +77,14 @@ void initEverything(void){
        test->addLayer(400);
        
        playerSpawnHill=new World();
-       
        playerSpawnHill->setBackground(BG_FOREST);
-       playerSpawnHill->generateFunc(1280,playerSpawnHillFunc);
+       
+       /*if((load=fopen("world.dat","rb"))){
+               playerSpawnHill->load(load);
+               fclose(load);
+       }else{*/
+               playerSpawnHill->generateFunc(1280,playerSpawnHillFunc);
+       //}
 
        /*
         *      Setup the current world, making the player initially spawn in `test`.
@@ -142,6 +141,12 @@ extern std::vector<int (*)(NPC *)> AIpreload;
 extern std::vector<NPC *> AIpreaddr;
 
 void destroyEverything(void){
+       //FILE *save;
+       
+       /*save = fopen("world.dat","wb");
+       playerSpawnHill->save(save);
+       fclose(save);*/
+       
        delete test;
        delete playerSpawnHill;
        
index 0eac3b265c6a9ada232f015920963ed84e634740..519c3f1832083bc35f6820d8f16798f538ef86fe 100644 (file)
@@ -16,8 +16,9 @@ static GLuint itemtex[ITEM_COUNT];
 void itemDraw(Player *p,ITEM_ID id);
 
 void initInventorySprites(void){
-       for(int i = 0;i<ITEM_COUNT;i++){
-               itemtex[i]=Texture::loadTexture(getItemTexturePath((ITEM_ID)i));
+       unsigned int i;
+       for(i = 0;i < ITEM_COUNT;i++){
+               itemtex[i] = Texture::loadTexture(getItemTexturePath((ITEM_ID)i));
        }
 }
 
@@ -31,7 +32,6 @@ Item::Item(ITEM_ID i, const char *n, ITEM_TYPE t, float w, float h, int m, const
        width = w;
        height = h;
        maxStackSize = m;
-       count = 0;
 
        name            = new char[strlen(n)+1];
        textureLoc      = new char[strlen(tl)+1];
@@ -58,34 +58,34 @@ void Inventory::setSelection(unsigned int s){
 }
 
 int Inventory::addItem(ITEM_ID id,unsigned char count){
-       std::cout << id << "," << inv[os].id << std::endl;
-       for(int i = 0; i < size; i++){
+       //std::cout << id << "," << inv[os].id << std::endl;
+       
+       for(unsigned int i = 0; i < size; i++){
                if(id == inv[i].id){
                        inv[i].count += count;
                        break;
-               }else if(id ){
+               }else if(id){
                        inv[os].id = id;
                        inv[os].count = count;
                        os++;
                        break;
                }
        }
+
 #ifdef DEBUG
        DEBUG_printf("Gave player %u more %s(s)(ID: %d).\n",count,item[id].name,item[id].id);
 #endif // DEBUG
+
        return 0;
 }
 
 int Inventory::takeItem(ITEM_ID id,unsigned char count){
-       unsigned int i;
-       for(i=0;i<size;i++){
-               if(inv[i].id==id){
+       for(unsigned int i = 0;i < size;i++){
+               if(inv[i].id == id){
 #ifdef DEBUG
                        DEBUG_printf("Took %u of player's %s(s).\n",count,item[i].name);
 #endif // DEBUG
                        inv[i].count-=count;
-                       if(item[i].count<0)
-                               return item[i].count*-1;
                        return 0;
                }
        }
@@ -93,10 +93,8 @@ int Inventory::takeItem(ITEM_ID id,unsigned char count){
 }
 
 void Inventory::draw(void){
-       unsigned int i=0;
        static unsigned int lop = 0;
-       float y,xoff;
-       static int numSlot = 7;
+       static unsigned int numSlot = 7;
        static std::vector<int>dfp(numSlot);
        static std::vector<Ray>iray(numSlot);
        static std::vector<vec2>curCoord(numSlot);
index e9b262f92c5158bfdb462d0058cbabc5aa1ca1a5..2c38f364dcdcaf5ecaafb08c0ebbdd4bdc534b39 100644 (file)
@@ -243,7 +243,7 @@ namespace ui {
        */
        
        float putString(const float x,const float y,const char *s){
-               unsigned int i=0,j;
+               unsigned int i=0;
                float xo=x,yo=y;
                vec2 add;
                
@@ -271,7 +271,7 @@ namespace ui {
        
        float putStringCentered(const float x,const float y,const char *s){
                unsigned int i = 0;
-               float width = 0, prev = 0;
+               float width = 0;
                
                do{
                        if(s[i]=='\n'){                 //      Handle newlines
@@ -299,7 +299,6 @@ namespace ui {
                                                        linc=0, //      Contains the number of letters that should be drawn.
                                                        size=0; //      Contains the full size of the current string.
                static char *ret = NULL;
-               unsigned int i;
                
                /*
                 *      Create a well-sized buffer if we haven't yet.
@@ -623,7 +622,7 @@ DONE:
                        }
                                if(SDL_KEY==SDLK_p)toggleBlack();
                                if(SDL_KEY==SDLK_F3)debug^=true;
-                               if(SDL_KEY==SDLK_b & SDL_KEY==SDLK_F3)posFlag^=true;
+                               if(((SDL_KEY==SDLK_b) & (SDL_KEY==SDLK_F3)))posFlag^=true;
                                if(SDL_KEY==SDLK_e){
                                        if(heyOhLetsGo == 0){
                                                heyOhLetsGo = loops;
index 3557121c4d32140266956c02abad8b291de64cf2..e5203dfc08d15c1823d5ee09d6edf6017f0b782c 100644 (file)
@@ -40,13 +40,7 @@ const float bgDraw[3][3]={
 };
 
 float worldGetYBase(World *w){
-       /*float base = 0;
-       World *ptr = w;
-       while(ptr->infront){
-               base+=DRAW_Y_OFFSET;
-               ptr=ptr->infront;
-       }*/
-       return /*base*/ GEN_MIN;
+       return w?GEN_MIN:0;
 }
 
 void World::setBackground(WORLD_BG_TYPE bgt){
@@ -60,7 +54,16 @@ void World::setBackground(WORLD_BG_TYPE bgt){
        }
 }
 
+void World::save(FILE *s){
+       fclose(s);
+}
+
+void World::load(FILE *s){
+       fclose(s);
+}
+
 World::World(void){
+       
        /*
         *      Nullify pointers to other worlds.
        */
@@ -70,8 +73,12 @@ World::World(void){
        toLeft  =
        toRight = NULL;
        
-       star = new vec2[100];                           //(vec2 *)calloc(100,sizeof(vec2));
-       memset(star,0,100*sizeof(vec2));
+       /*
+        *      Allocate and clear an array for star coordinates.
+       */
+       
+       star = new vec2[100];
+       memset(star,0,100 * sizeof(vec2));
 }
 
 void World::deleteEntities(void){
@@ -118,35 +125,38 @@ void World::generate(unsigned int width){ // Generates the world and sets all va
         * 
        */
        
-       if((lineCount = width + GEN_INC) <= 0)
+       if(width <= 0)
                abort();
+               
+       lineCount = width + GEN_INC;
        
        /*
         *      Allocate enough memory for the world to be stored.
        */
        
-       line = new struct line_t[lineCount]; //(struct line_t *)calloc(lineCount,sizeof(struct line_t));
-       memset(line,0,lineCount*sizeof(struct line_t));
+       line = new struct line_t[lineCount];
+       memset(line,0,lineCount * sizeof(struct line_t));
        
        /*
         *      Set an initial y to base generation off of, as generation references previous lines.
        */
        
-       line[0].y=GEN_INIT;
+       line[0].y = GEN_INIT;
        
        /*
         *      Populate every GEN_INCth line structure. The remaining lines will be based off of these.
        */
        
-       for(i=GEN_INC;i<lineCount;i+=GEN_INC){
+       for(i = GEN_INC;i < lineCount;i += GEN_INC){
                
                /*
                 *      Generate a y value, ensuring it stays within a reasonable range.
                */
                
-               line[i].y=rand() % 8 - 4 + line[i-GEN_INC].y;           // Add +/- 4 to the previous line
-                        if(line[i].y < GEN_MIN)line[i].y =  GEN_MIN;   // Minimum bound
-               else if(line[i].y > GEN_MAX)line[i].y =  GEN_MAX;       // Maximum bound
+               line[i].y = rand() % 8 - 4 + line[i - GEN_INC].y;       // Add +/- 4 to the previous line
+               
+                        if(line[i].y < GEN_MIN)line[i].y = GEN_MIN;    // Minimum bound
+               else if(line[i].y > GEN_MAX)line[i].y = GEN_MAX;        // Maximum bound
                
        }
        
@@ -154,7 +164,7 @@ void World::generate(unsigned int width){   // Generates the world and sets all va
         *      Generate values for the remaining lines here.
        */
        
-       for(i=0;i<lineCount-GEN_INC;i++){
+       for(i = 0;i < lineCount - GEN_INC;i++){
                
                /*
                 *      Every GEN_INCth line calculate the slope between the current line and the one
@@ -163,35 +173,31 @@ void World::generate(unsigned int width){ // Generates the world and sets all va
                 * 
                */
                
-               if(!(i%GEN_INC)){
+               if(!(i % GEN_INC))
                        
-                       inc=(line[i + GEN_INC].y - line[i].y) / (float)GEN_INC;
+                       inc = (line[i + GEN_INC].y - line[i].y) / (float)GEN_INC;
                        
-               }else{
-                       
-                       /*
-                        *      Add the increment to create the smooth slope.
-                       */
-                       
-                       line[i].y=line[i - 1].y + inc;
+               /*
+                *      Add the increment to create the smooth slope.
+               */
                        
-               }
+               else line[i].y = line[i - 1].y + inc;
                
                /*
                 *      Generate a color value for the line. This will be referenced in World->draw(),
                 *      by setting an RGB value of color (red), color - 50 (green), color - 100 (blue).
                */
                
-               line[i].color=rand() % 20 + 100; // 100 to 120
+               line[i].color = rand() % 20 + 100; // 100 to 120
 
                /*
                 *      Each line has two 'blades' of grass, here we generate random heights for them.
                */
                
-               line[i].gh[0]=(getRand() % 16) / 3.5 + 2;       // Not sure what the range resolves to here...
-               line[i].gh[1]=(getRand() % 16) / 3.5 + 2;       //
+               line[i].gh[0] = (getRand() % 16) / 3.5 + 2;     // Not sure what the range resolves to here...
+               line[i].gh[1] = (getRand() % 16) / 3.5 + 2;     //
                
-               line[i].gs=true;                                                        // Show the blades of grass (modified by the player)
+               line[i].gs = true;                                                      // Show the blades of grass (modified by the player)
                
        }
        
@@ -199,47 +205,80 @@ void World::generate(unsigned int width){ // Generates the world and sets all va
         *      Calculate the x coordinate to start drawing this world from so that it is centered at (0,0).
        */
        
-       x_start=0 - getWidth(this) / 2;
+       x_start = 0 - getWidth(this) / 2;
        
-       for(int i=0;i<100;i++){
-               star[i].x=getRand()%getTheWidth()-getTheWidth()/2;
-               star[i].y=getRand()%SCREEN_HEIGHT+100;
+       /*
+        *      Assign coordinates for the stars, seen at nighttime.
+       */
+       
+       for(i = 0;i < 100;i++){
+               star[i].x = getRand() % getTheWidth() - getTheWidth() / 2;
+               star[i].y = getRand() % SCREEN_HEIGHT + 100;
        }
 }
 
 void World::generateFunc(unsigned int width,float(*func)(float)){
        unsigned int i;
+       
+       /*
+        *      Check for a valid width.
+       */
+       
        if((lineCount = width) <= 0)
                abort();
-       line = new struct line_t[lineCount];    //(struct line_t *)calloc(lineCount,sizeof(struct line_t));
+       
+       /*
+        *      Allocate memory for the line array.
+       */
+       
+       line = new struct line_t[lineCount];
        memset(line,0,lineCount*sizeof(struct line_t));
-       for(i=0;i<lineCount;i++){
-               line[i].y=func(i);
-               if(line[i].y<0)line[i].y=0;
-               if(line[i].y>2000)line[i].y=2000;
-               line[i].color=rand() % 20 + 100;
-               line[i].gh[0]=(getRand() % 16) / 3.5 + 2;
-               line[i].gh[1]=(getRand() % 16) / 3.5 + 2;
-               line[i].gs=true;
+       
+       /*
+        *      Populate entries in the line array, using `func` to get y values.
+       */
+       
+       for(i = 0;i < lineCount;i++){
+               line[i].y = func(i);
+               
+               if(line[i].y <    0)line[i].y = 0;              // Minimum bound
+               if(line[i].y > 2000)line[i].y = 2000;   // Maximum bound
+               
+               line[i].color = rand() % 20 + 100;
+               
+               line[i].gh[0] = (getRand() % 16) / 3.5 + 2;
+               line[i].gh[1] = (getRand() % 16) / 3.5 + 2;
+               
+               line[i].gs = true;
        }
-       x_start=0 - getWidth(this) / 2;
        
-       for(int i=0;i<100;i++){
-               star[i].x=getRand()%getTheWidth()-getTheWidth()/2;
-               star[i].y=getRand()%SCREEN_HEIGHT+100;
+       x_start = 0 - getWidth(this) / 2;
+       
+       for(i = 0;i < 100;i++){
+               star[i].x = getRand() % getTheWidth() - getTheWidth() / 2;
+               star[i].y = getRand() % SCREEN_HEIGHT + 100;
        }
 }
 
 void World::update(Player *p,unsigned int delta){
-       p->loc.y+= p->vel.y                      *delta;
-       p->loc.x+=(p->vel.x*p->speed)*delta;
+       
+       /*
+        *      Update the player's coordinates.
+       */
+       
+       p->loc.y += p->vel.y                     * delta;
+       p->loc.x +=(p->vel.x * p->speed) * delta;
+
+       /*
+        *      Update coordinates of all entities except for structures.
+       */
 
        for(auto &e : entity){
                if(e->type != STRUCTURET)
                        e->loc.x += e->vel.x * delta;
                        e->loc.y += e->vel.y * delta;
                        if(e->vel.x < 0)e->left = true;
-               else if(e->vel.x > 0)e->left = false;
+          else if(e->vel.x > 0)e->left = false;
        }
 }
 
@@ -252,7 +291,8 @@ void World::draw(Player *p){
        static float yoff=DRAW_Y_OFFSET;        // Initialize stuff
        static int shade,bgshade;
        static World *current;
-       int i,is,ie,v_offset,cx_start,width;
+       unsigned int i,ie;
+       int is,v_offset,cx_start,width;
        struct line_t *cline;
        
        bgshade = worldShade << 1; // *2
@@ -290,8 +330,8 @@ void World::draw(Player *p){
         *      Draws stars if it is an appropriate time of day for them.
        */
 
-       if(((weather==DARK )&(tickCount%DAY_CYCLE)<DAY_CYCLE/2)   ||
-          ((weather==SUNNY)&(tickCount%DAY_CYCLE)>DAY_CYCLE*.75) ){
+       if((((weather==DARK )&(tickCount%DAY_CYCLE))<DAY_CYCLE/2)   ||
+          (((weather==SUNNY)&(tickCount%DAY_CYCLE))>DAY_CYCLE*.75) ){
                   
                if(tickCount % DAY_CYCLE){      // The above if statement doesn't check for exact midnight.
                                
@@ -530,7 +570,7 @@ LOOP2:
                 *      Calculate the line that the player is on
                */
                
-               int ph = (p->loc.x + p->width / 2 - x_start) / HLINE;
+               unsigned int ph = (p->loc.x + p->width / 2 - x_start) / HLINE;
                
                /*
                 *      If the player is on the ground, flatten the grass where the player is standing
@@ -587,8 +627,8 @@ LOOP2:
 }
 
 void World::singleDetect(Entity *e){
-       int i;
-       unsigned int j;
+       unsigned int i,j;
+       int l;
        
        /*
         *      Kill any dead entities.
@@ -635,17 +675,16 @@ void World::singleDetect(Entity *e){
                                                }
                                        }
                                        break;
+                               case PLAYERT:
+                                       std::cout<<"RIP "<<e->name<<"."<<std::endl;
+                                       exit(0);
+                                       break;
                                }
                                std::cout<<"Killed an entity..."<<std::endl;
                                entity.erase(entity.begin()+i);
                                return;
                        }
                }
-
-               std::cout<<"RIP "<<e->name<<"."<<std::endl;
-               exit(0);
-
-               return;
        }
        
        /*
@@ -660,8 +699,9 @@ void World::singleDetect(Entity *e){
                 *      Calculate the line that this entity is currently standing on.
                */
                
-               i=(e->loc.x + e->width / 2 - x_start) / HLINE;
-               if(i < 0) i=0;
+               l=(e->loc.x + e->width / 2 - x_start) / HLINE;
+               if(l < 0) l=0;
+               i = l;
                if(i > lineCount-1) i=lineCount-1;
                
                /*
@@ -690,8 +730,9 @@ void World::singleDetect(Entity *e){
                                do{
                                        e->loc.x+=.001 * e->vel.x>0?-1:1;
                                        
-                                       i=(e->loc.x - e->width / 2 - x_start) / HLINE;
-                                       if(i < 0){ e->alive = false; return; }
+                                       l=(e->loc.x - e->width / 2 - x_start) / HLINE;
+                                       if(l < 0){ e->alive = false; return; }
+                                       i = l;
                                        if(i > lineCount-1){ e->alive = false; return; }
                                }while(line[i].y>e->loc.y+ e->height);
                                
@@ -909,40 +950,62 @@ void IndoorWorld::generate(unsigned int width){           // Generates a flat area of wid
 }
 
 void IndoorWorld::draw(Player *p){
-       int i,ie,v_offset;
+       unsigned int i,ie;
+       int j,x,v_offset;
+       
+       /*
+        *      Draw the background.
+       */
        
        glEnable(GL_TEXTURE_2D);
+       
        bgTex->bind(0);
        glColor4ub(255,255,255,255);
-       glBegin(GL_QUADS);
-               for(i = x_start - SCREEN_WIDTH / 2;i < -x_start + SCREEN_WIDTH / 2; i += 1024){
-                       glTexCoord2i(1,1);glVertex2i(i     ,0);
-                       glTexCoord2i(0,1);glVertex2i(i+1024,0);
-                       glTexCoord2i(0,0);glVertex2i(i+1024,1024);
-                       glTexCoord2i(1,0);glVertex2i(i     ,1024);
+       
+       glBegin(GL_QUADS);      
+               for(j = x_start - SCREEN_WIDTH / 2;j < -x_start + SCREEN_WIDTH / 2; j += 512){
+                       glTexCoord2i(1,1);glVertex2i(j    ,0);
+                       glTexCoord2i(0,1);glVertex2i(j+512,0);
+                       glTexCoord2i(0,0);glVertex2i(j+512,512);
+                       glTexCoord2i(1,0);glVertex2i(j    ,512);
                }
        glEnd();
+       
        glDisable(GL_TEXTURE_2D);
        
-       v_offset=(p->loc.x-x_start)/HLINE;                                      // Calculate the player's offset in the array 'line' using the player's location 'vec'
-       i=v_offset-SCREEN_WIDTH/2;                                                      // um
-       if(i<0)i=0;                                                                                     // If the player is past the start of that world 'i' should start at the beginning
-                                                                                                               // of the world
-       ie=v_offset+SCREEN_WIDTH/2;                                                     // Set how many lines should be drawn (the drawing for loop loops from 'i' to 'ie')
-       if(ie>lineCount)ie=lineCount;                                           // If the player is past the end of that world 'ie' should contain the end of that world
-       //glClearColor(.3,.1,0,0);
+       /*
+        *      Calculate the starting and ending points to draw the ground from.
+       */
+       
+       v_offset = (p->loc.x - x_start) / HLINE;
+       j = v_offset - (SCREEN_WIDTH / 2 / HLINE) - GEN_INC;
+       if(j < 0)j = 0;
+       i = j;
+       
+       ie = v_offset + (SCREEN_WIDTH / 2 / HLINE) - GEN_INC;
+       if(ie > lineCount)ie = lineCount;
+       
+       /*
+        *      Draw the ground.
+       */
        
        glBegin(GL_QUADS);
-               for(i=i;i<ie-GEN_INC;i++){                                              // For lines in array 'line' from 'i' to 'ie'
+               for(;i < ie - GEN_INC;i++){
                        safeSetColor(150,100,50);
-                       glVertex2i(x_start+i*HLINE      ,line[i].y);    // Draw the base floor
-                       glVertex2i(x_start+i*HLINE+HLINE,line[i].y);
-                       glVertex2i(x_start+i*HLINE+HLINE,line[i].y-50);
-                       glVertex2i(x_start+i*HLINE              ,line[i].y-50);
+                       
+                       x = x_start + i * HLINE;
+                       glVertex2i(x            ,line[i].y);
+                       glVertex2i(x + HLINE,line[i].y);
+                       glVertex2i(x + HLINE,line[i].y - 50);
+                       glVertex2i(x            ,line[i].y - 50);
                }
        glEnd();
-       for(i=0;i<entity.size();i++)
-               entity[i]->draw();
+       
+       /*
+        *      Draw all entities.
+       */
+       
+       for(auto &e : entity) e->draw();
        p->draw();
 }