#include #include extern std::vectorentity; extern std::vectornpc; extern std::vectorbuild; 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; vel.x = 0; vel.y = 0; right = false; left = false; near = false; ticksToUse = 0; canMove = false; ground = false; name = (char*)malloc(16); getName(); } void Entity::draw(void){ //draws the entities glPushMatrix(); if(type==NPCT){ if(gender == MALE){ glColor3ub(255,255,255); }else if(gender == FEMALE){ glColor3ub(255,105,180); } if(NPCp(this)->aiFunc.size()){ glColor3ub(255,255,0); glRectf(loc.x+width/3,loc.y+height,loc.x+width*2/3,loc.y+height+width/3); } }else{ glColor3ub(255,255,255); } if(left){ glScalef(-1.0f,1.0f,1.0f); glTranslatef(0-width-loc.x*2,0,0); } glMatrixMode(GL_TEXTURE); glLoadIdentity(); glEnable(GL_TEXTURE_2D); if(type == PLAYERT){ static int texState = 0; static bool up = true; if(loops % (int)((float)5 / (float)speed) == 0){ if(up){ texState+=1; if(texState==2)up=false; }else if(!up){ texState-=1; if(texState==0)up=true; } }if(ground == 0){ glBindTexture(GL_TEXTURE_2D, texture[1]); } else if(vel.x != 0){ switch(texState){ case 0: glBindTexture(GL_TEXTURE_2D,texture[1]); break; case 1: glBindTexture(GL_TEXTURE_2D,texture[0]); break; case 2: glBindTexture(GL_TEXTURE_2D,texture[2]); break; } }else{ glBindTexture(GL_TEXTURE_2D,texture[0]); } }else{ glBindTexture(GL_TEXTURE_2D,texture[0]); } glBegin(GL_QUADS); glTexCoord2i(0,1);glVertex2i(loc.x, loc.y); glTexCoord2i(1,1);glVertex2i(loc.x + width, loc.y); glTexCoord2i(1,0);glVertex2i(loc.x + width, loc.y + height); glTexCoord2i(0,0);glVertex2i(loc.x, loc.y + height); glEnd(); glDisable(GL_TEXTURE_2D); glMatrixMode(GL_MODELVIEW); glPopMatrix(); if(near){ ui::setFontSize(14); ui::putText(loc.x,loc.y-ui::fontSize-HLINE/2,"%s",name); } } void Entity::wander(int timeRun, vec2 *v){ //this makes the entites wander about static int direction; //variable to decide what direction the entity moves if(ticksToUse == 0){ ticksToUse = timeRun; v->x = .008*HLINE; //sets the inital velocity of the entity direction = (getRand() % 3 - 1); //sets the direction to either -1, 0, 1 //this lets the entity move left, right, or stay still v->x *= direction; //changes the velocity based off of the direction } ticksToUse--; //removes one off of the entities timer } void Entity::getName(){ rewind(names); char buf,*bufs = (char *)malloc(16); int tempNum,max = 0; for(;!feof(names);max++){ fgets(bufs,16,(FILE*)names); } tempNum = rand()%max; rewind(names); for(int i=0;ispawn(loc.x + (float)(i - 5),100); //sets the position of the villager around the village } return entity.size(); } }