diff options
author | tom <tom@ground-control> | 2016-05-02 16:21:23 -0500 |
---|---|---|
committer | tom <tom@ground-control> | 2016-05-02 16:21:23 -0500 |
commit | 084d556f831832c1ca15d1e7cd52944815d9beea (patch) | |
tree | 675973a47691c06f19bd27a742c4888c02d66863 | |
parent | 42d7b3bb511333e242a74f360873deb64cd89522 (diff) |
implemented the location fully into entity
-rw-r--r-- | inc/entity.hpp | 5 | ||||
-rw-r--r-- | inc/location.hpp | 5 | ||||
-rw-r--r-- | src/creature.cpp | 49 | ||||
-rw-r--r-- | src/entity.cpp | 2 | ||||
-rw-r--r-- | 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(yPosition<yTarget) - yPosition+=speed; + if(L.y<yTarget) + L.y+=speed; else - yPosition-=speed; + L.y-=speed; } - else if(yPosition==yTarget) + else if(L.y==yTarget) { - if(xPosition<xTarget) - xPosition+=speed; + if(L.x<xTarget) + L.x+=speed; else - xPosition-=speed; + L.x-=speed; } - else if(xPosition<xTarget) + else if(L.x<xTarget) { - if(yPosition<yTarget) + if(L.y<yTarget) { - xPosition+=speed; - yPosition+=speed; + L.x+=speed; + L.y+=speed; } else { - xPosition+=speed; - yPosition-=speed; + L.x+=speed; + L.y-=speed; } } - else if (xPosition>xTarget) + else if (L.x>xTarget) { - if(yPosition<yTarget) + if(L.y<yTarget) { - xPosition-=speed; - yPosition+=speed; + L.x-=speed; + L.y+=speed; } else { - xPosition-=speed; - yPosition-=speed; + L.x-=speed; + L.y-=speed; } } @@ -160,7 +161,7 @@ bool Creature::Action() Location Creature::getLocation() { //returns location object of the specific creature - Location L(xPosition, yPosition, 1); + //Location L(xPosition, yPosition, 1); return L; } diff --git a/src/entity.cpp b/src/entity.cpp index 10a3ccc..909dd15 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -2,7 +2,7 @@ void Entity::Place() { - SDL_Rect rect = {xPosition, yPosition, width/8, height/8}; + SDL_Rect rect = {L.x, L.y, width/8, height/8}; SDL_RenderCopyEx(renderer,texture,NULL,&rect,degrees,NULL,SDL_FLIP_NONE); } diff --git a/src/resource.cpp b/src/resource.cpp index 8f1a4cf..9583f14 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -5,8 +5,9 @@ Resource::Resource(Window m, std::string s) texture = loadTexture(s, m); renderer = m.getRenderer(); - yPosition = rand()%800; - xPosition = rand()%1200; + L.y = rand()%800; + L.x = rand()%1200; + L.type = 2; amount = 100; } @@ -16,15 +17,16 @@ Resource::Resource(Window m, std::string s, Location z) texture = loadTexture(s, m); renderer = m.getRenderer(); - yPosition = z.y; - xPosition = z.x; - - amount = 100; + L.y = z.y; + L.x = z.x; + L.type = 2; + + amount = 100; } Location Resource::getLocation() { - Location L(xPosition,yPosition,2); + //Location L(xPosition,yPosition,2); return L; } |