aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordrumsetmonkey <abelleisle@roadrunner.com>2015-09-30 11:52:47 -0400
committerdrumsetmonkey <abelleisle@roadrunner.com>2015-09-30 11:52:47 -0400
commitc669b83b4f273df6f6ed824b997a77267fd0186f (patch)
treeb09e9bb8e3f5a8a0ce40850d39093b9da717aa62
parent5d4d0b5845d2b660e6c0d689c16572be538bbbe7 (diff)
NPC's spawn with a name and gender now
-rw-r--r--include/entities.h6
-rw-r--r--src/entities.cpp36
-rw-r--r--src/main.cpp5
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;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
diff --git a/src/main.cpp b/src/main.cpp
index 81b16e0..8b919a2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -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;
+ }
}
}
}