]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Added enum for types and improved NPCs
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 28 Sep 2015 12:47:43 +0000 (08:47 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 28 Sep 2015 12:47:43 +0000 (08:47 -0400)
include/common.h
include/entities.h
include/ui.h
src/entities.cpp
src/main.cpp
src/ui.cpp

index aa175bcadc6f89f40c8c84f54f78bb85c2ca3d75..922dd59f5ae48111f689615b170082b10fa5363c 100644 (file)
@@ -10,7 +10,8 @@
 #include <SDL2/SDL_image.h>
 #include <SDL2/SDL_opengl.h>
 
-typedef struct { float x; float y; } vec2;
+typedef struct { float x; float y; } vec2; 
+enum _TYPE {STRUCTURET = -1, PLAYERT = 0, NPCT = 1};
 
 #include <entities.h>
 
index 78d9a51039c68e45a4453934fe3993fcf9a4ed31..df81ad287455024a584423d80e55d8add749ff59 100644 (file)
@@ -9,7 +9,8 @@ public:
        float width;
        float height;
        float speed;
-       int type, subtype;
+       int subtype;
+       _TYPE type;
        vec2 loc;
        vec2 vel;
        bool right,left, canMove;
@@ -39,9 +40,9 @@ public:
 };
 class Structures : public Entity{
 public:
-       World *inside;
+       void *inside;
        Structures();
-       unsigned int spawn(int, float, float);
+       unsigned int spawn(_TYPE, float, float);
 };
 
 #endif // ENTITIES_H
index 8341a8c5d5c20058098b9a221e2b21af7809a625..dbcee3570ebcdeaac50bc7493f9f364ed0e7347d 100644 (file)
@@ -7,6 +7,8 @@
 namespace ui { // Functions are kept in a namespace simply
                                // for organization
 
+       extern vec2 mouse;
+
        extern bool debug;
        extern unsigned int fontSize;
 
index e93f23a7e1f344e30f10f7b21111ef1474a4f10e..421badbb66989a118321fc9c6270b14825e66166 100644 (file)
@@ -36,7 +36,7 @@ Player::Player(){
        width = HLINE * 8;
        height = HLINE * 12;
        speed = 1;
-       type = 0;
+       type = PLAYERT;
        subtype = 5;
        alive = true;
        ground = false;
@@ -50,7 +50,7 @@ NPC::NPC(){
        width = HLINE * 8;
        height = HLINE * 12;
        speed = 1;
-       type = 1;
+       type = NPCT;
        subtype = 0;
        alive = true;
        canMove = true;
@@ -61,17 +61,17 @@ void NPC::interact(){
 }
 
 Structures::Structures(){
-       type = -1;
+       type = STRUCTURET;
        speed = 0;
 }
 
-unsigned int Structures::spawn(int t, float x, float y){
+unsigned int Structures::spawn(_TYPE t, float x, float y){
        loc.x = x;
        loc.y = y;
        type = t;
 
        /*VILLAGE*/
-       if(type == -1){
+       if(type == STRUCTURET){
                width =  4 * HLINE;
                height = 4 * HLINE;
 
index 1e8b942d2d7b209e013604f219c1c22eef1d48b6..b24c7471f7c03eda38e64c7ac06d7681f34735a4 100644 (file)
@@ -109,8 +109,8 @@ int main(int argc, char *argv[]){
        entity[0]=&build[0];
        
        static unsigned int i;
-       build[0].spawn(-1,0,10);
-       for(i=0;i<entity.size()+1;i++){
+       build[0].spawn(STRUCTURET,0,10);
+       for(i=0;i<=entity.size();i++){
                entity[i]->inWorld=test;
        }
        
@@ -196,9 +196,9 @@ void logic(){
        ui::handleEvents();
        currentWorld->detect(player);
        for(int i=0;i<=entity.size();i++){
-               if(entity[i]->alive&&entity[i]->type == 1){
+               if(entity[i]->alive&&entity[i]->type == NPCT){
                        entity[i]->wander(90, &entity[i]->vel);
-                       std::cout<<"works"<<i<<std::endl;
+                       //std::cout<<"works"<<i<<std::endl;
                }
        }
 }
index 75bc5ee15f62fe0694f01c913a82dae7d7dbbc28..0789994750ebc0f9f6591b9ec1e5b85f81f40b63 100644 (file)
@@ -16,6 +16,7 @@ static bool dialogBoxExists=false;
 static const char *dialogBoxText=NULL;
 
 namespace ui {
+       vec2 mouse;
        bool debug=false;
        unsigned int fontSize;
        /*
@@ -132,6 +133,13 @@ namespace ui {
                        case SDL_QUIT:
                                gameRunning=false;
                                break;
+                       case SDL_MOUSEMOTION:
+                               mouse.x=e.motion.x;
+                               mouse.y=e.motion.y;
+                               break;
+                       /*
+                               KEYDOWN
+                       */
                        case SDL_KEYDOWN:
                                if(SDL_KEY==SDLK_ESCAPE)gameRunning=false;                                                      // Exit the game with ESC
                                if(SDL_KEY==SDLK_a){                                                                                            // Move left
@@ -166,6 +174,9 @@ namespace ui {
                                }
                                
                                break;
+                       /*
+                               KEYUP
+                       */      
                        case SDL_KEYUP:
                                if(SDL_KEY==SDLK_a)player->vel.x=0;     // Stop the player if movement keys are released
                                if(SDL_KEY==SDLK_d)player->vel.x=0;