summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-05-08 17:41:48 -0500
committertom <tom@ground-control>2015-05-08 17:41:48 -0500
commitce6b35d717de85a7ac45fa98197edf13e1820c8a (patch)
treedaca5dfebdb2c3de0ec851caf13c833cdee43c64
parent95fb44dd7009ddbb157fa4c54ddbab88a0af0c0b (diff)
added removal of resources once eaten, from the L and R vector
creatures that done move don't die right now, we need them to wander if they dont have a priority **difficult**
-rw-r--r--inc/creature.hpp2
-rw-r--r--inc/location.hpp2
-rw-r--r--inc/resource.hpp2
-rw-r--r--src/creature.cpp8
-rw-r--r--src/list.cpp36
-rw-r--r--src/resource.cpp4
6 files changed, 48 insertions, 6 deletions
diff --git a/inc/creature.hpp b/inc/creature.hpp
index 90b0b17..7c5c8cb 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -8,7 +8,7 @@ class Creature: public Entity
{
public:
Creature(Window m, std::string s);
- void Behavior();
+ int Behavior();
bool Action();
void Priority();
Location getLocation();
diff --git a/inc/location.hpp b/inc/location.hpp
index 71bf938..e45642d 100644
--- a/inc/location.hpp
+++ b/inc/location.hpp
@@ -7,7 +7,7 @@ class Location
Location(){x=y=type=0;}; //is this line needed?
Location(int x1, int y1, int t1){x=x1;y=y1;type=t1;};
- int x; //x-coordinate of entity
+ int x; //x-coordinate of entity
int y; //y-coordinate of entity
int type; //value associated with type of entity at location. 1: Creature, 2: Resource
};
diff --git a/inc/resource.hpp b/inc/resource.hpp
index 7417908..a1dd988 100644
--- a/inc/resource.hpp
+++ b/inc/resource.hpp
@@ -10,6 +10,8 @@ class Resource: public Entity
Resource(Window m, std::string s);
Resource(Window m, std::string s, Location z);
Location getLocation();
+ void eat(){amount-=10;};
+ int getAmount(){return amount;};
private:
int amount; //value associated with the amount of whatever (food, etc) left in the resource
diff --git a/src/creature.cpp b/src/creature.cpp
index 7f31003..c7b36ca 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -12,7 +12,7 @@ Creature::Creature(Window m, std::string s) //Constructor
xPosition=xTarget=rand()%1200;
}
-void Creature::Behavior()
+int Creature::Behavior()
{
health-=1; //Decrements health each time a behavior is executed
this->Priority(); //Checks which action has priority (doesn't really do this right now)
@@ -20,7 +20,9 @@ void Creature::Behavior()
if(this->Action())
{
health+=10;
+ return 2;
}
+ return 0;
}
void Creature::Priority()
@@ -40,6 +42,10 @@ void Creature::Priority()
bool Creature::Action()
{
//If the distance is close, will return an bool
+
+ //if(xPosition == xTarget && yPosition == yTarget)
+ // return false;
+
if(sqrt(pow(xPosition - xTarget, 2) + pow(yPosition - yTarget, 2)) < 2)
return true;
diff --git a/src/list.cpp b/src/list.cpp
index 6317d45..cd69f8f 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -46,12 +46,42 @@ void List::Place()
void List::Behavior()
{
- int i, j;
+ int i, j, k, l;
std::vector<Location> Z;
for(i = 0; i < C.size(); i++)
{
- C[i].Behavior(); //executes the behavior of the creature at i
+ int o = C[i].Behavior();
+
+ if(o==1)
+ {
+ //If next to creature
+ }
+
+ if(o==2)
+ {
+ //If next to resource
+ Location tmp = C[i].getLocation();
+ for(k=0;k<R.size();k++)
+ {
+ if(Distance(tmp,R[k].getLocation())<2)
+ {
+ R[k].eat();
+ if(R[k].getAmount()<=0)
+ {
+ R.erase(R.begin()+k);
+ for(l=0;l<L.size();l++)
+ {
+ if(L[l].x==R[k].getLocation().x&&L[l].y==R[k].getLocation().y) // NEED TO OPERATOR OVERLOAD FOR THIS
+ {
+ L.erase(L.begin()+l);
+ std::cout << "removing";
+ }
+ }
+ }
+ }
+ }
+ }
//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++)
@@ -62,7 +92,7 @@ void List::Behavior()
Z.clear(); //clear vector Z for next creature
// This kills the creature
- if(C[i].getHealth()==0)
+ if(C[i].getHealth()<=0)
{
Location z = C[i].getLocation();
Resource r = Resource(main,"img/Cdead.png",z);
diff --git a/src/resource.cpp b/src/resource.cpp
index 6a228fe..4f12e2d 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -8,6 +8,8 @@ Resource::Resource(Window m, std::string s) //Constructor
//Initialized random position coordinates
yPosition = rand()%800;
xPosition = rand()%1200;
+
+ amount = 100;
}
Resource::Resource(Window m, std::string s, Location z)
@@ -17,6 +19,8 @@ Resource::Resource(Window m, std::string s, Location z)
yPosition = z.y;
xPosition = z.x;
+
+ amount = 100;
}
Location Resource::getLocation() //Returns resource object