diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 12 | ||||
-rw-r--r-- | src/gameplay.cpp | 28 | ||||
-rw-r--r-- | src/world.cpp | 67 |
3 files changed, 54 insertions, 53 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index acc45bd..9a3730e 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -1,14 +1,11 @@ #include <entities.h> #include <ui.h> -std::vector<Entity *> entity; -std::vector<NPC *> npc; -std::vector<Structures *> build; -std::vector<Mob *> mob; - extern FILE* names; extern unsigned int loops; +extern World *currentWorld; + void Entity::spawn(float x, float y){ //spawns the entity you pass to it based off of coords and global entity settings loc.x = x; loc.y = y; @@ -317,10 +314,7 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure * with type NPC by using polymorphism. */ - npc.push_back(new NPC()); - npc.back()->spawn(loc.x+(i-5),100); - - entity.push_back(npc.back()); + currentWorld->addNPC(loc.x+(i-5),100); } break; diff --git a/src/gameplay.cpp b/src/gameplay.cpp index 39d0675..e9d0a74 100644 --- a/src/gameplay.cpp +++ b/src/gameplay.cpp @@ -5,11 +5,6 @@ extern World *currentWorld; extern Player *player; -extern std::vector<Entity *> entity; -extern std::vector<Structures *> build; -extern std::vector<Mob *> mob; -extern std::vector<NPC *> npc; - extern void mainLoop(void); @@ -23,7 +18,7 @@ int giveTestQuest(NPC *speaker){ unsigned int i; ui::dialogBox(speaker->name,"Here, have a quest!"); player->qh.assign("Test"); - npc[1]->addAIFunc(compTestQuest,true); + currentWorld->npc[1]->addAIFunc(compTestQuest,true); return 0; } @@ -75,9 +70,7 @@ void initEverything(void){ * Create a structure (this will create villagers when spawned). */ - build.push_back(new Structures()); - entity.push_back(build.back()); - build.back()->spawn(STRUCTURET,(rand()%120*HLINE),10); + currentWorld->addStructure(STRUCTURET,(rand()%120*HLINE),10); /* * Generate an indoor world and link the structure to it. @@ -85,26 +78,19 @@ void initEverything(void){ IndoorWorld *iw=new IndoorWorld(); iw->generate(200); - build.back()->inside=iw; + currentWorld->build.back()->inside=iw; /* * Spawn a mob. */ - mob.push_back(new Mob(MS_RABBIT)); - entity.push_back(mob.back()); - mob.back()->spawn(200,100); - - mob.push_back(new Mob(MS_BIRD)); - entity.push_back(mob.back()); - mob.back()->spawn(-500,500); + currentWorld->addMob(MS_RABBIT,200,100); + currentWorld->addMob(MS_BIRD,-500,500); /* * Link all the entities that were just created to the initial world, and setup a test AI function. */ - npc[0]->addAIFunc(giveTestQuest,false); - for(i=0;i<entity.size();i++){ - entity[i]->inWorld=currentWorld; - } + currentWorld->npc[0]->addAIFunc(giveTestQuest,false); + } diff --git a/src/world.cpp b/src/world.cpp index b0f419d..09da095 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -19,9 +19,6 @@ #define INDOOR_FLOOR_HEIGHT 100 // Defines how high the base floor of an IndoorWorld should be -extern std::vector<Entity *> entity; -extern std::vector<Structures *> build; - bool worldInside = false; float worldGetYBase(World *w){ @@ -188,6 +185,19 @@ World::~World(void){ free(line); } +void World::update(Player *p,unsigned int delta){ + p->loc.y+= p->vel.y *delta; + p->loc.x+=(p->vel.x*p->speed)*delta; + + 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; + } +} + int worldShade = 0; void World::draw(Player *p){ @@ -271,9 +281,8 @@ LOOP2: */ if(current==this){ - for(i=0;i<entity.size();i++){ - if(entity[i]->inWorld==this && entity[i]->type == STRUCTURET) - entity[i]->draw(); + for(i=0;i<build.size();i++){ + build[i]->draw(); } } @@ -393,11 +402,10 @@ LOOP2: * Draw non-structure entities. */ - for(i=0;i<entity.size();i++){ - if(entity[i]->inWorld==this && entity[i]->type != STRUCTURET) - entity[i]->draw(); - } - + for(i=0;i<npc.size();i++) + npc[i]->draw(); + for(i=0;i<mob.size();i++) + mob[i]->draw(); } /* @@ -511,14 +519,29 @@ void World::detect(Player *p){ * Handle all remaining entities in this world. */ - for(i=0;i<entity.size();i++){ - - if(entity[i]->inWorld==this){ - - singleDetect(entity[i]); - - } - } + for(i=0;i<entity.size();i++) + singleDetect(entity[i]); +} + +void World::addStructure(_TYPE t,float x,float y){ + build.push_back(new Structures()); + build.back()->spawn(t,x,y); + + entity.push_back(build.back()); +} + +void World::addMob(int t,float x,float y){ + mob.push_back(new Mob(t)); + mob.back()->spawn(x,y); + + entity.push_back(mob.back()); +} + +void World::addNPC(float x,float y){ + npc.push_back(new NPC()); + npc.back()->spawn(x,y); + + entity.push_back(npc.back()); } /* @@ -644,9 +667,7 @@ void IndoorWorld::draw(Player *p){ glVertex2i(x_start+i*HLINE ,line[i].y-50); } glEnd(); - for(i=0;i<entity.size();i++){ - if(entity[i]->inWorld==this) - entity[i]->draw(); - } + for(i=0;i<entity.size();i++) + entity[i]->draw(); p->draw(); } |