summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Barrett <tombarrett@cornell.engr.siu.edu>2015-05-08 14:25:47 -0500
committerTom Barrett <tombarrett@cornell.engr.siu.edu>2015-05-08 14:25:47 -0500
commit88579e8ab934e1ec50ee4c1a5e2d39b1308c1db9 (patch)
tree93deb6db9cc318e903b7c9b47d5cfee21f323741
parent39d7fe95633baafe4539f604186b151f30401a39 (diff)
all creatures should die now, and leave a body which is a resource.
they currently don't have a way to gain health so they live short sad lives. haven't compiled or tested, so more work needs to be done
-rw-r--r--inc/creature.hpp3
-rw-r--r--inc/resource.hpp1
-rw-r--r--src/list.cpp14
-rw-r--r--src/resource.cpp9
4 files changed, 23 insertions, 4 deletions
diff --git a/inc/creature.hpp b/inc/creature.hpp
index 9bb73ee..cfdd317 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -9,10 +9,11 @@ class Creature: public Entity
public:
Creature(Window m, std::string s);
void Behavior();
- void Action();
+ void Action();
void Priority();
Location getLocation();
void giveKnown(std::vector<Location> Z){location = Z;};
+ int getHealth(){return health;};
private:
int xTarget; //x-coordinate of creature's target position
diff --git a/inc/resource.hpp b/inc/resource.hpp
index 383e9ef..7417908 100644
--- a/inc/resource.hpp
+++ b/inc/resource.hpp
@@ -8,6 +8,7 @@ class Resource: public Entity
{
public:
Resource(Window m, std::string s);
+ Resource(Window m, std::string s, Location z);
Location getLocation();
private:
diff --git a/src/list.cpp b/src/list.cpp
index 2140a75..e5ac9b8 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -17,6 +17,8 @@ List::List(Window m) //Constructor
R.push_back(Y);
L.push_back(Y.getLocation());
}
+
+ main = &m;
}
void List::Place()
@@ -47,15 +49,21 @@ void List::Behavior()
int i, j;
std::vector<Location> Z;
- //
for(i = 0; i < C.size(); i++)
{
C[i].Behavior(); //executes the behavior of the creature at i
+
+ // This kills the creature
+ if(C[i].getHealth()==0)
+ {
+ Location z = C[i].getLocation();
+ R.push_back(Resource(main,"img/Cdead.png",z));
+ 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 5044760..e549214 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -12,6 +12,15 @@ Resource::Resource(Window m, std::string s) //Constructor
xPosition = xStart;
}
+Resource::Resource(Window m, std::string s, Location z)
+{
+ texture = loadTexture(s, m);
+ renderer = m.getRenderer();
+
+ yPosition = z.y;
+ xPosition = z.x;
+}
+
Location Resource::getLocation() //Returns resource object
{
Location L(xPosition,yPosition,2);