From b0f7e8d2caa72ab1fe93fa58dbfa841750d96037 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Mon, 9 Nov 2015 08:47:39 -0500 Subject: draw/handle all layers --- Changelog | 9 ++++++ include/entities.h | 3 +- include/world.h | 3 +- src/entities.cpp | 2 ++ src/gameplay.cpp | 12 ++------ src/world.cpp | 80 ++++++++++++++++++++++++++++++------------------------ 6 files changed, 62 insertions(+), 47 deletions(-) diff --git a/Changelog b/Changelog index b286376..dba1ecf 100644 --- a/Changelog +++ b/Changelog @@ -257,3 +257,12 @@ - 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 diff --git a/include/entities.h b/include/entities.h index 422d5d8..53efc63 100644 --- a/include/entities.h +++ b/include/entities.h @@ -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); diff --git a/include/world.h b/include/world.h index 754f3c7..9d7a33b 100644 --- a/include/world.h +++ b/include/world.h @@ -76,7 +76,7 @@ public: std::vector mob; std::vector 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); diff --git a/src/entities.cpp b/src/entities.cpp index 9a3730e..b076684 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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){ diff --git a/src/gameplay.cpp b/src/gameplay.cpp index e9d0a74..3b13dfe 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -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. */ diff --git a/src/world.cpp b/src/world.cpp index 09da095..63604fe 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -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;idraw(); - } + 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;idraw(); - for(i=0;idraw(); } /* @@ -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;ibehind){ + 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: "<inside<<" "<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; } -- cgit v1.2.3