]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added mob class, and basic skirl
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 8 Oct 2015 13:09:15 +0000 (09:09 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 8 Oct 2015 13:09:15 +0000 (09:09 -0400)
include/common.h
include/entities.h
main.cpp
out/entities.o
out/gameplay.o
src/entities.cpp
src/gameplay.cpp

index 3015b11060c7d318df3c6e72f5ffae663e432c05..9ed4182d7441ebb96fe927dec6c3f66024a9f72c 100644 (file)
@@ -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{
index dacf394de2e924b81bbc0817cfc40189162e6c40..833ebe1cb7676ab5a946b37eb44ab231bb2f6b9c 100644 (file)
@@ -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
index 41f8e79a55cb9759deeea86327e0159318628f36..5010606e2cb8403f3281c37aea5af344e166752e 100644 (file)
--- 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;
@@ -232,17 +233,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);
                        }
                }
        }
index 69472f4d15531e3d4470b354fcd64af3aea0ebff..486d4488c643b08dca39bd4a1b36a76979946dd2 100644 (file)
Binary files a/out/entities.o and b/out/entities.o differ
index 68948530d0f9d52cdcc983aef889e6080b3981df..21500b570accdb7e00efdbb56ec2f5be12b4e2f3 100644 (file)
Binary files a/out/gameplay.o and b/out/gameplay.o differ
index 127adaef0f937c30264166d364397ce81828e637..565c369e023c818829c7a83e9e15f9ca1687e618 100644 (file)
@@ -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
index b6b939ab9a23dab0636d6f8f156c5c107b0fc74c..ac38559636be7045ee60f377b57794ae7560e397 100644 (file)
@@ -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);
 
@@ -50,11 +52,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++){