]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
draw/handle all layers
authorClyne Sullivan <tullivan99@gmail.com>
Mon, 9 Nov 2015 13:47:39 +0000 (08:47 -0500)
committerClyne Sullivan <tullivan99@gmail.com>
Mon, 9 Nov 2015 13:47:39 +0000 (08:47 -0500)
Changelog
include/entities.h
include/world.h
src/entities.cpp
src/gameplay.cpp
src/world.cpp

index b28637660b61b5a88c473fe6bfc317daa9c38005..dba1ecfb5c4f8e29d948412eaf1a5343704c79ec 100644 (file)
--- a/Changelog
+++ b/Changelog
        - created 'storyboard' for first few player areas
        - improved flashlight
        - made some minor improvements to world appearance
+
+11/9/2015:
+==========
+
+       - gave world's their own entity/mob/npc/build arrays
+       - cleaned up for loops (switched most to `for(auto :)`
+       - added drawing/handling of entities on all layers at all times
+       - removed building entering/exiting
+       - andy broke SDL cuz he's bad
index 422d5d80566deefb32d55fd8c654e7e22573c2d1..53efc639968bf91d0720257edf1882f281b50841 100644 (file)
@@ -36,8 +36,6 @@ class Entity{
 public:
        Inventory *inv;
 
-       void *inWorld;
-
        float width;    //width and height of the player
        float height;
        float speed;    //speed of the play
@@ -95,6 +93,7 @@ public:
 
 class Structures : public Entity{
 public:
+       void *inWorld;
        void *inside;
        Structures();
        unsigned int spawn(_TYPE, float, float);
index 754f3c7fec7a4800c82cb0031ee755fcf2081dc2..9d7a33bd9619ff253569cdd23bc7a90b39f10997 100644 (file)
@@ -76,7 +76,7 @@ public:
        std::vector<Mob                 *>      mob;
        std::vector<Entity              *>      entity;
        
-       void addStructure(_TYPE t,float x,float y);
+       void addStructure(_TYPE t,float x,float y,void *inside);
        void addMob(int t,float x,float y);
        void addNPC(float x,float y);
        
@@ -173,6 +173,7 @@ float worldGetYBase(World *w);
  
 class IndoorWorld : public World {
 public:
+       World *outside;
        IndoorWorld(void);
        ~IndoorWorld(void);
        
index 9a3730e1ec7f6778d6cca07a4fdc3938dae56bde..b076684b2cfacf960c2b960da638cfdb14dd1f54 100644 (file)
@@ -64,6 +64,8 @@ Structures::Structures(){ //sets the structure type
        near  = false;
        
        tex = new Texturec(1,"assets/house1.png");
+       
+       inWorld = NULL;
 }
 
 Mob::Mob(int sub){
index e9d0a742f11dbf0fbf92a5af46612d35c3213bd3..3b13dfe66d93ff39217b0e94fa7c35ce763ac96d 100644 (file)
@@ -64,22 +64,16 @@ void initEverything(void){
        */
        
        player=new Player();
-       player->spawn(0,5000);
+       player->spawn(0,200);
        
        /*
         *      Create a structure (this will create villagers when spawned).
        */
        
-       currentWorld->addStructure(STRUCTURET,(rand()%120*HLINE),10);
-       
-       /*
-        *      Generate an indoor world and link the structure to it. 
-       */
-       
        IndoorWorld *iw=new IndoorWorld();
        iw->generate(200);
-       currentWorld->build.back()->inside=iw;
-
+       currentWorld->addStructure(STRUCTURET,(rand()%120*HLINE),10,iw);
+       
        /*
         *      Spawn a mob. 
        */
index 09da095e0fb1eec390ab638c0f648cc8689949bd..63604fe73a522a9a2681e677d265c04c3b68e01a 100644 (file)
@@ -276,14 +276,14 @@ LOOP2:
        shade*=-1;
        
        /*
-        *      Draw structures in the current layer if we're on the one we started at. We draw
-        *      structures behind the dirt/grass so that the buildings corners don't stick out.
+        *      Draw structures. We draw structures behind the dirt/grass so that the building's
+        *      corners don't stick out.
        */
        
-       if(current==this){
-               for(i=0;i<build.size();i++){
-                       build[i]->draw();
-               }
+       for(auto &b : current->build){
+               b->loc.y+=(yoff-DRAW_Y_OFFSET);
+               b->draw();
+               b->loc.y-=(yoff-DRAW_Y_OFFSET);
        }
        
        /*
@@ -362,8 +362,22 @@ LOOP2:
        glEnd();
        
        /*
-        *      If we're drawing the closest/last world, handle and draw the player and entities in
-        *      the world.
+        *      Draw non-structure entities.
+       */
+               
+       for(auto &n : current->npc){
+               n->loc.y+=(yoff-DRAW_Y_OFFSET);
+               n->draw();
+               n->loc.y-=(yoff-DRAW_Y_OFFSET);
+       }
+       for(auto &m : current->mob){
+               m->loc.y+=(yoff-DRAW_Y_OFFSET);
+               m->draw();
+               m->loc.y-=(yoff-DRAW_Y_OFFSET);
+       }
+       
+       /*
+        *      If we're drawing the closest/last world, handle and draw the player.
        */
        
        if(current==this){
@@ -398,14 +412,6 @@ LOOP2:
                
                p->draw();
                
-               /*
-                *      Draw non-structure entities.
-               */
-               
-               for(i=0;i<npc.size();i++)
-                       npc[i]->draw();
-               for(i=0;i<mob.size();i++)
-                       mob[i]->draw();
        }
        
        /*
@@ -507,7 +513,7 @@ void World::singleDetect(Entity *e){
 }
 
 void World::detect(Player *p){
-       unsigned int i;
+       World *hey;
        
        /*
         *      Handle the player. 
@@ -519,13 +525,32 @@ void World::detect(Player *p){
         *      Handle all remaining entities in this world. 
        */
        
-       for(i=0;i<entity.size();i++)
-               singleDetect(entity[i]);
+        hey = this;
+
+LOOP:
+
+       if(hey->behind){
+               hey=hey->behind;
+               goto LOOP;
+       }
+
+LOOP2:
+       
+       for(auto &e : hey->entity)
+               singleDetect(e);
+               
+       if(hey->infront){
+               hey=hey->infront;
+               goto LOOP2;
+       }
 }
 
-void World::addStructure(_TYPE t,float x,float y){
+void World::addStructure(_TYPE t,float x,float y,void *inside){
        build.push_back(new Structures());
        build.back()->spawn(t,x,y);
+       build.back()->inside=inside;
+       
+       std::cout<<"inside: "<<build.back()->inside<<" "<<inside<<std::endl;
        
        entity.push_back(build.back());
 }
@@ -591,21 +616,6 @@ World *World::goWorldFront(Player *p){
 }
 
 World *World::goInsideStructure(Player *p){
-       unsigned int i;
-       for(i=0;i<build.size();i++){
-               if(build[i]->inWorld==this){
-                       if(p->loc.x                        > build[i]->loc.x &&
-                          p->loc.x + p->width < build[i]->loc.x + build[i]->width){
-                               worldInside = true;
-                               return (World *)build[i]->inside;
-                       }
-               }else if(build[i]->inside==this){
-                       p->loc.x=build[i]->loc.x + build[i]->width / 2 - p->width / 2;
-                       p->loc.y=build[i]->loc.y + HLINE;
-                       worldInside = false;
-                       return (World *)build[i]->inWorld;
-               }
-       }
        return this;
 }