aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClyne Sullivan <tullivan99@gmail.com>2015-10-08 09:12:18 -0400
committerClyne Sullivan <tullivan99@gmail.com>2015-10-08 09:12:18 -0400
commitc88533e59e961a029f6bb4777932434a9ca517f4 (patch)
tree96a384874d8e9f49becc989fcc535f8d511a0c34
parent6e9eda2e22e79a90395387f4014c975044ea8d05 (diff)
parentedf746b79c8646c2c21c04997d23c94c1ee8adcd (diff)
merge
-rw-r--r--include/common.h3
-rw-r--r--include/entities.h37
-rw-r--r--main.cpp27
-rw-r--r--src/entities.cpp67
-rw-r--r--src/gameplay.cpp12
5 files changed, 113 insertions, 33 deletions
diff --git a/include/common.h b/include/common.h
index ed2ed9e..b7c13e7 100644
--- a/include/common.h
+++ b/include/common.h
@@ -17,7 +17,8 @@ typedef struct { float x; float y; }vec2;
enum _TYPE { //these are the main types of entities
STRUCTURET = -1,
PLAYERT = 0,
- NPCT = 1
+ NPCT = 1,
+ MOBT = 2
};
enum GENDER{
diff --git a/include/entities.h b/include/entities.h
index dacf394..833ebe1 100644
--- a/include/entities.h
+++ b/include/entities.h
@@ -44,11 +44,11 @@ public:
void spawn(float, float);
void draw(void);
- void wander(int, vec2*);
+ virtual void wander(int, vec2*){}
void getName();
virtual void interact(){}
-private:
int ticksToUse; //The variable for deciding how long an entity should do a certain task
+private:
};
class Player : public Entity{
@@ -64,6 +64,7 @@ public:
NPC();
void addAIFunc(int (*func)(NPC *));
void interact();
+ void wander(int, vec2*);
};
class Structures : public Entity{
public:
@@ -71,5 +72,37 @@ public:
Structures();
unsigned int spawn(_TYPE, float, float);
};
+class Mob : public Entity{
+public:
+ Mob();
+ void wander(int, vec2*);
+};
#endif // ENTITIES_H
+
+/**
+ENTITY TYPES
+-1 STRUCTURES
+|->1 Village
+|->2 Castle
+|
+0 PLAYERS
+|->Player
+|
+1 NPCS
+|->0 Base
+|->1 Merchant
+|
+2 MOBS
+|->1 Skirl
+
+
+
+
+
+
+
+
+
+
+**/ \ No newline at end of file
diff --git a/main.cpp b/main.cpp
index f0ca288..b8f82f0 100644
--- a/main.cpp
+++ b/main.cpp
@@ -21,6 +21,7 @@ Player *player;
std::vector<Entity*>entity;
std::vector<NPC>npc;
std::vector<Structures *>build;
+std::vector<Mob>mob;
int mx, my;
FILE* names;
@@ -234,17 +235,21 @@ void logic(){
ui::handleEvents();
currentWorld->detect(player);
for(int i=0;i<=entity.size();i++){
- if(entity[i]->alive&&entity[i]->type == NPCT){
- 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){
- entity[i]->near=true;
- if(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;
- //Mix_PlayChannel( -1, horn, 0);
- }
- }else entity[i]->near=false;
+ if(entity[i]->alive){
+ if(entity[i]->type == NPCT){
+ 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){
+ entity[i]->near=true;
+ if(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;
+ //Mix_PlayChannel( -1, horn, 0);
+ }
+ }else entity[i]->near=false;
+ }
+ }if(entity[i]->type == MOBT){
+ entity[i]->wander(90,&entity[i]->vel);
}
}
}
diff --git a/src/entities.cpp b/src/entities.cpp
index 127adae..565c369 100644
--- a/src/entities.cpp
+++ b/src/entities.cpp
@@ -23,14 +23,13 @@ void Entity::spawn(float x, float y){ //spawns the entity you pass to it based o
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);
+ }if(gender == MALE){
+ glColor3ub(255,255,255);
+ }else if(gender == FEMALE){
+ glColor3ub(255,105,180);
}
}else{
glColor3ub(255,255,255);
@@ -89,18 +88,6 @@ void Entity::draw(void){ //draws the entities
}
}
-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);
@@ -167,6 +154,19 @@ NPC::NPC(){ //sets all of the NPC specific traits on object creation
inv = new Inventory(NPC_INV_SIZE);
}
+void NPC::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 NPC::addAIFunc(int (*func)(NPC *)){
aiFunc.push_back(func);
}
@@ -215,3 +215,36 @@ unsigned int Structures::spawn(_TYPE t, float x, float y){ //spawns a structure
return entity.size();
}
}
+Mob::Mob(){
+ width = HLINE * 10;
+ height = HLINE * 8;
+ speed = 1;
+ type = MOBT; //sets type to MOB
+ subtype = 1; //SKIRL
+ alive = true;
+ canMove = true;
+ near = false;
+ texture[0] = loadTexture("assets/NPC.png");
+ texture[1] = 0;
+ texture[2] = 0;
+ inv = new Inventory(NPC_INV_SIZE);
+}
+
+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;
+ if(ground && direction != 0){
+ v->y=.08;
+ loc.y+=HLINE*1;
+ ground=false;
+ 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
+ }
+} \ No newline at end of file
diff --git a/src/gameplay.cpp b/src/gameplay.cpp
index a690203..57132f5 100644
--- a/src/gameplay.cpp
+++ b/src/gameplay.cpp
@@ -8,6 +8,8 @@ extern std::vector<Entity*>entity;
extern std::vector<NPC>npc;
extern std::vector<Structures *>build;
extern Player *player;
+extern std::vector<Mob>mob;
+
extern void mainLoop(void);
@@ -56,11 +58,17 @@ void initEverything(void){
entity.push_back(new Entity());
build.push_back(new Structures());
entity[0]=build[0];
-
- build[0]->spawn(STRUCTURET,0,10);
+
+ build[0]->spawn(STRUCTURET,(rand()%120*HLINE),10);
IndoorWorld *iw=new IndoorWorld();
iw->generate(200);
build[0]->inside=iw;
+
+ entity.push_back(new Mob()); //create a new entity of NPC type
+ mob.push_back(Mob()); //create new NPC
+ entity[entity.size()] = &mob[mob.size()-1]; //set the new entity to have the same traits as an NPC
+ entity[entity.size()-1]->spawn(200,100); //sets the position of the villager around the village
+ entity.pop_back();
NPCp(entity[1])->addAIFunc(giveTestQuest);
for(i=0;i<entity.size()+1;i++){