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);
class IndoorWorld : public World {
public:
+ World *outside;
IndoorWorld(void);
~IndoorWorld(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.
*/
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);
}
/*
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){
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();
}
/*
}
void World::detect(Player *p){
- unsigned int i;
+ World *hey;
/*
* Handle the player.
* 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());
}
}
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;
}