diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/entities.cpp | 102 | ||||
-rw-r--r-- | src/ui.cpp | 3 | ||||
-rw-r--r-- | src/world.cpp | 8 |
3 files changed, 72 insertions, 41 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index 57a20ef..627946b 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -13,6 +13,14 @@ extern Player *player; extern const char *itemName; +std::string sTexLoc[] = { "assets/townhall.png", + "assets/house1.png", + "assets/house2.png", + "assets/house1.png", + "assets/house1.png", + "assets/fountain1.png", + "assets/lampPost1.png"}; + void getRandomName(Entity *e){ unsigned int tempNum,max=0; char *bufs; @@ -119,9 +127,6 @@ Structures::Structures(){ //sets the structure type alive = false; near = false; - tex = new Texturec(3,"assets/house1.png", "assets/house2.png", "assets/fountain1.png"); - ntex = new Texturec(1, "assets/house1N.png"); - inWorld = NULL; name = NULL; @@ -282,7 +287,7 @@ void Entity::draw(void){ //draws the entities case MS_DOOR: case MS_PAGE: default: - glActiveTexture(GL_TEXTURE0 + 0); + glActiveTexture(GL_TEXTURE0); tex->bind(0); break; } @@ -290,27 +295,25 @@ void Entity::draw(void){ //draws the entities case STRUCTURET: for(auto &strt : currentWorld->build){ if(this == strt){ - if(strt->bsubtype == HOUSE){ - glActiveTexture(GL_TEXTURE1); - ntex->bind(0); - //When rendering an objectwith this program. - glActiveTexture(GL_TEXTURE0 + 0); - tex->bind(0); - //glBindSampler(0, linearFiltering); - - - }else if(strt->bsubtype == HOUSE2){ - glActiveTexture(GL_TEXTURE0 + 0); - tex->bind(1); - }else if(strt->bsubtype == FOUNTAIN){ - glActiveTexture(GL_TEXTURE0 + 0); - tex->bind(2); + switch(strt->bsubtype){ + /*case HOUSE: + glActiveTexture(GL_TEXTURE1); + ntex->bind(0); + //When rendering an objectwith this program. + glActiveTexture(GL_TEXTURE0); + tex->bind(0); + //glBindSampler(0, linearFiltering); + break;*/ + default: + glActiveTexture(GL_TEXTURE0); + tex->bind(0); + break; } } } break; default: - glActiveTexture(GL_TEXTURE0 + 0); + glActiveTexture(GL_TEXTURE0); tex->bind(0); break; } @@ -442,16 +445,16 @@ void Object::interact(void){ * point to have non-normal traits so it could be invisible or invincible... */ -unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y, World *oi){ +unsigned int Structures::spawn(BUILD_SUB sub, float x, float y, World *oi){ loc.x = x; loc.y = y; - type = t; - + type = STRUCTURET; + alive = true; - width = 50 * HLINE; - height = 40 * HLINE; bsubtype = sub; + int s = -1; + s = sub; inWorld = oi; @@ -459,20 +462,45 @@ unsigned int Structures::spawn(_TYPE t, BUILD_SUB sub, float x, float y, World * * tempN is the amount of entities that will be spawned in the village. Currently the village * will spawn bewteen 2 and 7 villagers for the starting hut. */ - + /* tex = new Texturec(7,"assets/townhall.png", + "assets/house1.png", + "assets/house2.png", + "assets/house1.png", + "assets/house1.png", + "assets/fountain1.png", + "assets/lampPost1.png")*/; + unsigned int tempN = (getRand() % 5 + 2); - - for(unsigned int i = 0;i < tempN;i++){ - - /* - * This is where the entities actually spawn. A new entity is created - * with type NPC. - */ - - inWorld->addNPC(loc.x + i * HLINE ,100); - + switch(s){ + case HOUSE: + tex = new Texturec(1, sTexLoc[s].c_str()); + width = 50 * HLINE; + height = 40 * HLINE; + for(unsigned int i = 0;i < tempN;i++){ + + /* + * This is where the entities actually spawn. A new entity is created + * with type NPC. + */ + + oi->addNPC(loc.x + i * HLINE ,100); + + } + break; + case FOUNTAIN: + tex = new Texturec(1, sTexLoc[s].c_str()); + width = 50 * HLINE; + height = 40 * HLINE; + break; + case LAMP_POST: + tex = new Texturec(1, sTexLoc[s].c_str()); + width = 10 * HLINE; + height = 40 * HLINE; + oi->addLight({x+SCREEN_WIDTH/2,y+30*HLINE},{1.0f,1.0f,1.0f}); + break; + default: + break; } - return 0; } @@ -822,6 +822,9 @@ DONE: case SDLK_f: currentWorld->addLight({player->loc.x + SCREEN_WIDTH/2, player->loc.y},{1.0f,1.0f,1.0f}); break; + case SDLK_g: + currentWorld->addStructure(LAMP_POST, player->loc.x, player->loc.y, currentWorld); + break; default: break; } diff --git a/src/world.cpp b/src/world.cpp index e2c6aa9..451a022 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1057,9 +1057,9 @@ LOOOOP: goto LOOOOP; } } -void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){ +void World::addStructure(BUILD_SUB sub, float x,float y,World *inside){ build.push_back(new Structures()); - build.back()->spawn(t,sub,x,y,this); + build.back()->spawn(sub,x,y,this); build.back()->inWorld=this; build.back()->inside = (World *)inside; ((IndoorWorld *)inside)->outside = this; @@ -1067,11 +1067,11 @@ void World::addStructure(_TYPE t,BUILD_SUB sub, float x,float y,World *inside){ entity.push_back(build.back()); } -void World::addVillage(int bCount, int npcMin, int npcMax,_TYPE t,World *inside){ +void World::addVillage(int bCount, int npcMin, int npcMax,World *inside){ std::cout << npcMin << ", " << npcMax << std::endl; //int xwasd; for(int i = 0; i < bCount; i++){ - addStructure(t,HOUSE,x_start + (i * 300),100,inside); + addStructure(HOUSE,x_start + (i * 300),100,inside); /*std::cout<<"1\n"; HERE: xwasd = (rand()%(int)x+1000*HLINE); |