From 113bb97e4ce7db5bc275e0dccf7c790c86cda5d7 Mon Sep 17 00:00:00 2001 From: drumsetmonkey Date: Mon, 28 Sep 2015 08:47:43 -0400 Subject: Added enum for types and improved NPCs --- include/common.h | 3 ++- include/entities.h | 7 ++++--- include/ui.h | 2 ++ src/entities.cpp | 10 +++++----- src/main.cpp | 8 ++++---- src/ui.cpp | 11 +++++++++++ 6 files changed, 28 insertions(+), 13 deletions(-) diff --git a/include/common.h b/include/common.h index aa175bc..922dd59 100644 --- a/include/common.h +++ b/include/common.h @@ -10,7 +10,8 @@ #include #include -typedef struct { float x; float y; } vec2; +typedef struct { float x; float y; } vec2; +enum _TYPE {STRUCTURET = -1, PLAYERT = 0, NPCT = 1}; #include diff --git a/include/entities.h b/include/entities.h index 78d9a51..df81ad2 100644 --- a/include/entities.h +++ b/include/entities.h @@ -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 diff --git a/include/ui.h b/include/ui.h index 8341a8c..dbcee35 100644 --- a/include/ui.h +++ b/include/ui.h @@ -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; diff --git a/src/entities.cpp b/src/entities.cpp index e93f23a..421badb 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 1e8b942..b24c747 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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;iinWorld=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"<vel.x=0; // Stop the player if movement keys are released if(SDL_KEY==SDLK_d)player->vel.x=0; -- cgit v1.2.3