diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-22 09:27:55 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-22 09:27:55 -0400 |
commit | c99d7fb5e5c047709ccd4823e39ccb16c153eecb (patch) | |
tree | 9b77ae63cd8876e8d449ba4cb6ad82ad88b16b55 /src/entities.cpp | |
parent | 95f1817ebf57e54ca43181198c1782838f424492 (diff) | |
parent | d15062f7f2563761660e665d0940d9c0d1a7883c (diff) |
screw npcs
Diffstat (limited to 'src/entities.cpp')
-rw-r--r-- | src/entities.cpp | 122 |
1 files changed, 88 insertions, 34 deletions
diff --git a/src/entities.cpp b/src/entities.cpp index ce983e8..7a4da65 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -33,10 +33,11 @@ Player::Player(){ //sets all of the player specific traits on object creation subtype = 0; maxHealth = 100; health = maxHealth; - texture[0] = loadTexture("assets/player.png"); - texture[1] = loadTexture("assets/player1.png"); - texture[2] = loadTexture("assets/player2.png"); + alive = true; + ground = false; + near = true; inv = new Inventory(PLAYER_INV_SIZE); + tex = new Texturec(3, "assets/player.png", "assets/player1.png", "assets/player2.png"); } NPC::NPC(){ //sets all of the NPC specific traits on object creation @@ -45,16 +46,22 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation speed = 1; type = NPCT; //sets type to npc subtype = 0; - texture[0] = loadTexture("assets/NPC.png"); + alive = true; + canMove = true; + near = false; + texture[0] = Texture::loadTexture("assets/NPC.png"); texture[1] = 0; texture[2] = 0; + //tex = new Texturec("assets/NPC.png"); inv = new Inventory(NPC_INV_SIZE); } Structures::Structures(){ //sets the structure type type = STRUCTURET; speed = 0; - texture[0] = loadTexture("assets/house1.png"); + alive = true; + near = false; + texture[0] = Texture::loadTexture("assets/house1.png"); texture[1] = 0; texture[2] = 0; } @@ -65,8 +72,11 @@ Mob::Mob(){ speed = 1; type = MOBT; //sets type to MOB subtype = 1; //SKIRL - texture[0] = loadTexture("assets/rabbit.png"); - texture[1] = loadTexture("assets/rabbit1.png"); + alive = true; + canMove = true; + near = false; + texture[0] = Texture::loadTexture("assets/rabbit.png"); + texture[1] = Texture::loadTexture("assets/rabbit1.png"); texture[2] = 0; inv = new Inventory(NPC_INV_SIZE); } @@ -105,25 +115,22 @@ void Entity::draw(void){ //draws the entities } } if(ground == 0){ - glBindTexture(GL_TEXTURE_2D, texture[1]); - } - if(ground == 0){ - glBindTexture(GL_TEXTURE_2D, texture[1]); + glBindTexture(GL_TEXTURE_2D, tex->image[0]); }else if(vel.x != 0){ switch(texState){ case 0: - glBindTexture(GL_TEXTURE_2D,texture[1]); + glBindTexture(GL_TEXTURE_2D,tex->image[1]); break; case 1: - glBindTexture(GL_TEXTURE_2D,texture[0]); + glBindTexture(GL_TEXTURE_2D,tex->image[0]); break; case 2: - glBindTexture(GL_TEXTURE_2D,texture[2]); + glBindTexture(GL_TEXTURE_2D,tex->image[2]); break; } } else{ - glBindTexture(GL_TEXTURE_2D,texture[0]); + glBindTexture(GL_TEXTURE_2D,tex->image[0]); } }else if(type == MOBT){ switch(subtype){ @@ -137,7 +144,9 @@ void Entity::draw(void){ //draws the entities default: break; } - }else{ + }/*else if(type == NPCT){ + glBindTexture(GL_TEXTURE_2D, tex->image); + }*/else{ glBindTexture(GL_TEXTURE_2D,texture[0]); } glColor3ub(255,255,255); @@ -192,8 +201,29 @@ void Player::interact(){ //the function that will cause the player to search for } +/* + * NPC::wander, this makes the npcs wander around the near area + * + * timeRun This variable is the amount of gameloop ticks the entity will wander for + * + * *v This is a pointer to whatever vec2 value is passed to it, usually the value + * passed is the entities vec2 for coordinates. Since the value is a pointer + * the memory address passed to it is directly modified. +*/ + void NPC::wander(int timeRun, vec2 *v){ //this makes the entites wander about + /* + * Direction is the variable that decides what direction the entity will travel in + * the value is either -1, 0, or 1. -1 being left, 0 means that the npc will stay still + * and a value of 1 makes the entity move to the right + */ static int direction; //variable to decide what direction the entity moves + /* + * Ticks to use is a variable in the entity class that counts the total ticks that need to be used + * + * This loop only runs when ticksToUse is 0, this means that the speed, direction, etc... Will be + * calculated only after the npc has finished his current walking state + */ if(ticksToUse == 0){ ticksToUse = timeRun; v->x = .008*HLINE; //sets the inital velocity of the entity @@ -232,6 +262,16 @@ void NPC::interact(){ //have the npc's interact back to the player } } +/* + * This spawns the structures + * + * Structures::spawn This allows us to spawn buildings and large amounts of entities with it. + * Passed are the type and x and y coordinates. These set the x and y coords + * of the structure being spawned, the type pass just determines what rules to follow + * when spawing the structure and entities. In theory this function can also spawn + * void spawn points for large amounts of entities. This would allow for the spawn + * point to have non-normal traits so it could be invisible or invincible... +*/ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure based off of type and coords loc.x = x; loc.y = y; @@ -240,15 +280,21 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure health = maxHealth = 1; /*VILLAGE*/ - //spawns a village - //spawns between 1 and 5 villagers around the village if(type == STRUCTURET){ loc.y=100; width = 50 * HLINE; height = 40 * HLINE; + /* + * tempN is the amount of entities that will be spawned in the village. As of 10/21/2015 the village + * can spawn bewteen 2 and 7 villagers for the starting hut. + */ int tempN = (getRand() % 5 + 2); //amount of villagers that will spawn for(int i=0;i<tempN;i++){ + /* + * This is where the entities actually spawn. + * A new entity is created with type NPC so polymorphism can be used + */ entity.push_back(new NPC()); //create a new entity of NPC type NPCp(entity[entity.size()-1])->spawn(loc.x + (float)(i - 5),100); //sets the position of the villager around the village } @@ -256,22 +302,30 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure } } +/* + * Mob::wander this is the function that makes the mobs wander around + * + * See NPC::wander for the explaination of the arguments variables +*/ void Mob::wander(int timeRun, vec2* v){ - if(subtype == 1){ //SKIRL - static int direction; //variable to decide what direction the entity moves - if(ticksToUse == 0){ - ticksToUse = timeRun; - direction = (getRand() % 3 - 1); //sets the direction to either -1, 0, 1 - //this lets the entity move left, right, or stay still - if(direction==0)ticksToUse/=2; - v->x *= direction; //changes the velocity based off of the direction - } - if(ground && direction != 0){ - v->y=.15; - loc.y+=HLINE*.25; - ground=false; - v->x = (.07*HLINE)*direction; //sets the inital velocity of the entity - } - ticksToUse--; //removes one off of the entities timer + switch(subtype){ //SKIRL + case 1: + static int direction; //variable to decide what direction the entity moves + if(ticksToUse == 0){ + ticksToUse = timeRun; + direction = (getRand() % 3 - 1); //sets the direction to either -1, 0, 1 + //this lets the entity move left, right, or stay still + if(direction==0)ticksToUse/=2; + v->x *= direction; //changes the velocity based off of the direction + } + if(ground && direction != 0){ + v->y=.15; + loc.y+=HLINE*.25; + ground=false; + v->x = (.07*HLINE)*direction; //sets the inital velocity of the entity + } + ticksToUse--; //removes one off of the entities timer + break; + default:break; } } |