From c669b83b4f273df6f6ed824b997a77267fd0186f Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Wed, 30 Sep 2015 11:52:47 -0400 Subject: NPC's spawn with a name and gender now --- include/entities.h | 6 +++++- src/entities.cpp | 36 ++++++++++++++++++++++++++++++------ src/main.cpp | 5 ++++- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/include/entities.h b/include/entities.h index 4f0c338..3d2bbef 100644 --- a/include/entities.h +++ b/include/entities.h @@ -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 diff --git a/src/entities.cpp b/src/entities.cpp index 273d038..b40ddd4 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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;iwander((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 <<"["< "<< entity[i]->name << ", " << (std::string)(entity[i]->gender == MALE ? "Male" : "Female") << std::endl; + } } } } -- cgit v1.2.3