From 084d556f831832c1ca15d1e7cd52944815d9beea Mon Sep 17 00:00:00 2001 From: tom Date: Mon, 2 May 2016 16:21:23 -0500 Subject: implemented the location fully into entity --- inc/entity.hpp | 5 ++--- inc/location.hpp | 5 +++-- src/creature.cpp | 49 +++++++++++++++++++++++++------------------------ src/entity.cpp | 2 +- src/resource.cpp | 16 +++++++++------- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/inc/entity.hpp b/inc/entity.hpp index 803c1e4..3555c62 100644 --- a/inc/entity.hpp +++ b/inc/entity.hpp @@ -11,9 +11,8 @@ class Entity SDL_Texture* loadTexture(std::string path, Window main); protected: - //Location L; - int xPosition, yPosition; //Coordinates of entity on window - int height, width; //Dimensions of image on window + Location L; + int height, width; //Dimensions of image on window int degrees = 0; SDL_Texture* texture; SDL_Renderer* renderer; diff --git a/inc/location.hpp b/inc/location.hpp index 9f50863..0e3ee23 100644 --- a/inc/location.hpp +++ b/inc/location.hpp @@ -5,8 +5,9 @@ class Location { public: Location(int x1, int y1, int t1){x=x1;y=y1;type=t1;}; - int x; //x-coordinate of entity - int y; //y-coordinate of entity + Location(){x=y=type=0;}; + int x; + int y; int type; //value associated with type of entity at location. 1: Creature, 2: Resource }; diff --git a/src/creature.cpp b/src/creature.cpp index 83b9f4d..01882a3 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -8,9 +8,10 @@ Creature::Creature(Window m, std::string s) maxHealth = 1000; hunger = 0; - yPosition=yTarget=rand()%800; - xPosition=xTarget=rand()%1200; - hasTarget = false; + L.y=yTarget=rand()%800; + L.x=xTarget=rand()%1200; + + hasTarget = false; wandering = false; able = true; n=0; @@ -108,49 +109,49 @@ bool Creature::Action() } //Makes moves towards target coordinates - if(xPosition==xTarget) + if(L.x==xTarget) { - if(yPositionxTarget) + else if (L.x>xTarget) { - if(yPosition