From 83d23230a3d71d76ee5e0368e071273beaa6d1b4 Mon Sep 17 00:00:00 2001 From: tom Date: Fri, 8 May 2015 16:16:59 -0500 Subject: death now works properly --- inc/list.hpp | 2 +- inc/window.hpp | 1 + src/creature.cpp | 2 +- src/list.cpp | 22 ++++++++++++---------- src/resource.cpp | 8 +++----- 5 files changed, 18 insertions(+), 17 deletions(-) diff --git a/inc/list.hpp b/inc/list.hpp index dc5c412..f370d24 100644 --- a/inc/list.hpp +++ b/inc/list.hpp @@ -16,7 +16,7 @@ class List private: //vectors containing objects of each type - Window * main;//will be needed for adding R's and C's after constructor. + Window main = Window("no");//will be needed for adding R's and C's after constructor. std::vector R; std::vector C; std::vector L; diff --git a/inc/window.hpp b/inc/window.hpp index d3436d8..073a106 100644 --- a/inc/window.hpp +++ b/inc/window.hpp @@ -17,6 +17,7 @@ class Window { public: Window(); + Window(std::string){}; void Destroy(); void Clear(); diff --git a/src/creature.cpp b/src/creature.cpp index 5c3bb8e..dcc8337 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -14,7 +14,7 @@ Creature::Creature(Window m, std::string s) //Constructor void Creature::Behavior() { - health--; //Decrements health each time a behavior is executed + health-=5; //Decrements health each time a behavior is executed this->Priority(); //Checks which action has priority (doesn't really do this right now) this->Action(); //Does action } diff --git a/src/list.cpp b/src/list.cpp index ff38a68..6317d45 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -18,7 +18,7 @@ List::List(Window m) //Constructor L.push_back(Y.getLocation()); } - main = &m; + main = m; } void List::Place() @@ -52,21 +52,23 @@ void List::Behavior() for(i = 0; i < C.size(); i++) { C[i].Behavior(); //executes the behavior of the creature at i - + + //if the distance between the creature and L[j] is less than 200, insert L[j] into vector Z. + for(j = 0; j < L.size(); j++) + if(200>(Distance(C[i].getLocation(),L[j]))) + Z.push_back(L[j]); + + C[i].giveKnown(Z); //sets creature's target location? + Z.clear(); //clear vector Z for next creature + // This kills the creature if(C[i].getHealth()==0) { Location z = C[i].getLocation(); - R.push_back(Resource(*main,"img/Cdead.png",z)); + Resource r = Resource(main,"img/Cdead.png",z); + R.push_back(r); C.erase(C.begin()+i); } - - for(j = 0; j < L.size(); j++) - if(200>(Distance(C[i].getLocation(),L[j]))) //if the distance between the creature and L[j] is less than 200, insert L[j] into vector Z. - Z.push_back(L[j]); - - C[i].giveKnown(Z); //sets creature's target location? - Z.clear(); //clear vector Z for next creature } } diff --git a/src/resource.cpp b/src/resource.cpp index e549214..6a228fe 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -6,17 +6,15 @@ Resource::Resource(Window m, std::string s) //Constructor renderer = m.getRenderer(); //Initialized random position coordinates - int yStart = rand()%800; - int xStart = rand()%1200; - yPosition = yStart; - xPosition = xStart; + yPosition = rand()%800; + xPosition = rand()%1200; } Resource::Resource(Window m, std::string s, Location z) { texture = loadTexture(s, m); renderer = m.getRenderer(); - + yPosition = z.y; xPosition = z.x; } -- cgit v1.2.3