]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
NPC's spawn with a name and gender now
authordrumsetmonkey <abelleisle@roadrunner.com>
Wed, 30 Sep 2015 15:52:47 +0000 (11:52 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Wed, 30 Sep 2015 15:52:47 +0000 (11:52 -0400)
include/entities.h
src/entities.cpp
src/main.cpp

index 4f0c338c172198217584770be9cb4948b702a2bc..3d2bbefb4fd04f2191f9a65fa9fd104693eb85f2 100644 (file)
@@ -5,6 +5,8 @@
 
 #define NPCp(n) ((NPC *)n)
 
+extern FILE* names;
+
 class Entity{
 public:
        void *inWorld;
@@ -25,13 +27,15 @@ public:
        bool alive;                               //the flag for whether or not the entity is alive
        unsigned char ground;     //variable for testing what ground the entity is on to apply certain traits
 
+       char* name;
+       GENDER gender;
        unsigned int texture[];   //TODO: ADD TEXTURES
 
        
        void spawn(float, float);
        void draw(void);
        void wander(int, vec2*);
-       char* getName();
+       void getName();
        virtual void interact(){}
 private:
        int ticksToUse; //The variable for deciding how long an entity should do a certain task
index 273d0384b17059150a7ca075a27853a82e26d000..b40ddd45756b29899ef3612ee84e77852698ad7c 100644 (file)
@@ -14,11 +14,16 @@ void Entity::spawn(float x, float y){       //spawns the entity you pass to it based o
        ticksToUse = 0;
        canMove = false;
        ground = false;
+       name = (char*)malloc(16);
+       getName();
 }
 
 void Entity::draw(void){               //draws the entities
        if(type==NPCT)
-               glColor3ub(0,0,100);
+               if(gender == MALE)
+                       glColor3ub(0,0,100);
+               else if(gender == FEMALE)
+                       glColor3ub(255,105,180);
        else if(type==STRUCTURET)
                glColor3ub(100,0,100);
        glRectf(loc.x,loc.y,loc.x+width,loc.y+height);
@@ -36,10 +41,29 @@ void Entity::wander(int timeRun, vec2 *v){ //this makes the entites wander about
        ticksToUse--; //removes one off of the entities timer
 }
 
-char* Entity::getName(){
-       char* buf;
-
-       return buf;
+void Entity::getName(){
+       rewind(names);
+       char buf;
+       char* bufs = (char*)malloc(16);
+       int max = 0;
+       int tempNum = rand()%105;
+       for(int i=0;i<tempNum;i++){
+               fgets(bufs,16,(FILE*)names);
+       }
+       buf = fgetc(names);
+       if(buf == 'm'){
+               gender = MALE;
+               std::puts("Male");
+       }else if(buf == 'f'){
+               gender = FEMALE;
+               std::puts("Female");
+       }
+       if((fgets(bufs,16,(FILE*)names)) != NULL){
+               std::puts(bufs);
+               bufs[strlen(bufs)-1] = 0;
+               name = bufs;
+       }
+       //delete(bufs);
 }
 
 Player::Player(){ //sets all of the player specific traits on object creation
@@ -100,7 +124,7 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure
                width =  20 * HLINE;
                height = 16 * HLINE;
 
-               int tempN = 2;//(getRand() % 5 + 1); //amount of villagers that will spawn
+               int tempN = (getRand() % 5 + 1); //amount of villagers that will spawn
                for(int i=0;i<tempN;i++){
                        entity.push_back(new NPC()); //create a new entity of NPC type
                        npc.push_back(NPC()); //create new NPC
index 81b16e0a2ac0e22054de41a256f1b759388365d8..8b919a215d63c4f53856852c6605ff9f6ba088f6 100644 (file)
@@ -147,6 +147,7 @@ int main(int argc, char *argv[]){
        **************************/
        
     //closes the window and frees resources
+    //fclose(names);
     SDL_GL_DeleteContext(mainGLContext);
     SDL_DestroyWindow(window);
     return 0;
@@ -225,8 +226,10 @@ void logic(){
                        entity[i]->wander((rand()%120 + 30), &entity[i]->vel);
                        if( pow((entity[i]->loc.x - player->loc.x),2) + pow((entity[i]->loc.y - player->loc.y),2) <= pow(40*HLINE,2)){
                                if(mx >= entity[i]->loc.x && mx <= entity[i]->loc.x + entity[i]->width && my >= entity[i]->loc.y && my <= entity[i]->loc.y + entity[i]->width
-                                && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT)))
+                                && (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(SDL_BUTTON_RIGHT))){
                                        entity[i]->interact();
+                                       std::cout <<"["<<i<<"] -> "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl;
+                               }
                        }
                }
        }