summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-05-08 16:16:59 -0500
committertom <tom@ground-control>2015-05-08 16:16:59 -0500
commit83d23230a3d71d76ee5e0368e071273beaa6d1b4 (patch)
treed617951e5d897ab79efdc061d541c860c2569fd5
parentef2d82b47654dff444263ae149aec0d416a4f405 (diff)
death now works properly
-rw-r--r--inc/list.hpp2
-rw-r--r--inc/window.hpp1
-rw-r--r--src/creature.cpp2
-rw-r--r--src/list.cpp22
-rw-r--r--src/resource.cpp8
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<Resource> R;
std::vector<Creature> C;
std::vector<Location> 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;
}