diff options
-rw-r--r-- | include/common.h | 1 | ||||
-rw-r--r-- | include/entities.h | 6 | ||||
-rw-r--r-- | src/entities.cpp | 35 | ||||
-rw-r--r-- | src/main.cpp | 27 |
4 files changed, 44 insertions, 25 deletions
diff --git a/include/common.h b/include/common.h index dde3c4a..aa175bc 100644 --- a/include/common.h +++ b/include/common.h @@ -4,6 +4,7 @@ ///THIS FILE IS USED FOR VARIABLES THAT WILL BE ACCESED BY MULTIPLE CLASSES/FILES #include <iostream> +#include <vector> #include <cstdlib> #include <SDL2/SDL.h> #include <SDL2/SDL_image.h> diff --git a/include/entities.h b/include/entities.h index bc277cd..e7389dc 100644 --- a/include/entities.h +++ b/include/entities.h @@ -3,8 +3,6 @@ #include <common.h> -extern int npcAmt; - class Entity{ public: float width; @@ -37,10 +35,6 @@ public: NPC(); void interact(); }; - -extern Entity *entnpc[32]; //The NPC base -extern NPC npc[32]; - class Structures : public Entity{ public: Structures(); diff --git a/src/entities.cpp b/src/entities.cpp index 6058e41..9c18313 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -1,8 +1,8 @@ #include <entities.h> -int npcAmt=0; -Entity *entnpc[32]; -NPC npc[32]; +extern std::vector<Entity*>entity; +extern std::vector<NPC>npc; +extern std::vector<Structures>build; void Entity::spawn(float x, float y){ loc.x = x; @@ -21,12 +21,12 @@ void Entity::draw(void){ } void Entity::wander(int timeRun, vec2 *v){ - static int hey; + static int direction; if(ticksToUse == 0){ ticksToUse = timeRun; - v->x = .00010; - hey = (getRand() % 3 - 1); - v->x *= hey; + v->x = .01*HLINE; + direction = (getRand() % 3 - 1); + v->x *= direction; } ticksToUse--; } @@ -46,7 +46,7 @@ void Player::interact(){ NPC::NPC(){ width = HLINE * 8; - height = HLINE * 18; + height = HLINE * 12; speed = 1; type = 0; subtype = 0; @@ -74,14 +74,17 @@ void Structures::spawn(int t, float x, float y){ width = 4 * HLINE; height = 4 * HLINE; - int tempN = (getRand() % 5 + 1); - npcAmt = tempN; - - for(int i = 0;i<eAmt(entnpc);i++){ - npc[i].alive = true; - entnpc[i] = &npc[i]; - npc[i].type = -1; //this will make the NPC spawn the start of a village - entnpc[i]->spawn(loc.x + (float)(i - 5) / 8,0); //this will spawn the start of a village + //int tempN = (getRand() % 5 + 1); + int tempN = 2; + for(int i=0;i<tempN;i++){ + entity.push_back(new Entity()); + npc.push_back(NPC()); + std::cout<<"NPC:"<<npc.size()<<std::endl; + std::cout<<"Entity:"<<entity.size()<<std::endl; + entity[entity.size()] = &npc[npc.size()-1]; + entity[entity.size()]->alive=true; + entity[entity.size()]->type = 1; + entity[entity.size()]->spawn(loc.x + (float)(i - 5) / 8,0); } } } diff --git a/src/main.cpp b/src/main.cpp index 4f4c13a..a5bee95 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,10 @@ static unsigned int tickCount = 0, World *currentWorld=NULL; Player *player; +std::vector<Entity*>entity; +std::vector<NPC>npc; +std::vector<Structures>build; + void logic(); void render(); @@ -87,8 +91,12 @@ int main(int argc, char *argv[]){ player=new Player(); player->spawn(0,100); - currentTime=millis(); + entity.push_back(new Entity());//create the blank first element for the player; + build.push_back(Structures()); + entity[0]=&build[0]; + build[0].spawn(-1,0,10); + currentTime=millis(); while(gameRunning){ prevTime = currentTime; currentTime = millis(); @@ -99,6 +107,8 @@ int main(int argc, char *argv[]){ prevTime = millis(); } + player->loc.y+=player->vel.y*deltaTime; + player->loc.x+=player->vel.x*deltaTime; render(); } @@ -134,6 +144,12 @@ void render(){ player->draw(); ui::putString(0,0,"Hello"); + for(int i=0;i<=entity.size();i++){ + entity[i]->draw(); + entity[i]->loc.x += entity[i]->vel.x * deltaTime; + entity[i]->loc.y += entity[i]->vel.y * deltaTime; + } + /************************** **** CLOSE THE LOOP **** **************************/ @@ -145,6 +161,11 @@ void render(){ void logic(){ ui::handleEvents(); currentWorld->detect(&player->loc,&player->vel,player->width); - player->loc.y+=player->vel.y*deltaTime; - player->loc.x+=player->vel.x*deltaTime; + for(int i=0;i<=entity.size();i++){ + currentWorld->detect(&entity[i]->loc,&entity[i]->vel,entity[i]->width); + if(entity[i]->alive==true&&entity[i]->type == 1){ + entity[i]->wander(90, &entity[i]->vel); + } + } + } |