summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-05-08 16:24:37 -0500
committertom <tom@ground-control>2015-05-08 16:24:37 -0500
commit95fb44dd7009ddbb157fa4c54ddbab88a0af0c0b (patch)
treed7e679ea139a99194c0242bc4982c482d071f5de
parent83d23230a3d71d76ee5e0368e071273beaa6d1b4 (diff)
they may eat if they can reach food in time
-rw-r--r--inc/creature.hpp2
-rw-r--r--src/creature.cpp13
2 files changed, 10 insertions, 5 deletions
diff --git a/inc/creature.hpp b/inc/creature.hpp
index cfdd317..90b0b17 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -9,7 +9,7 @@ class Creature: public Entity
public:
Creature(Window m, std::string s);
void Behavior();
- void Action();
+ bool Action();
void Priority();
Location getLocation();
void giveKnown(std::vector<Location> Z){location = Z;};
diff --git a/src/creature.cpp b/src/creature.cpp
index dcc8337..7f31003 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -14,9 +14,13 @@ Creature::Creature(Window m, std::string s) //Constructor
void Creature::Behavior()
{
- health-=5; //Decrements health each time a behavior is executed
+ health-=1; //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
+
+ if(this->Action())
+ {
+ health+=10;
+ }
}
void Creature::Priority()
@@ -33,11 +37,11 @@ void Creature::Priority()
}
}
-void Creature::Action()
+bool Creature::Action()
{
//If the distance is close, will return an bool
if(sqrt(pow(xPosition - xTarget, 2) + pow(yPosition - yTarget, 2)) < 2)
- return; //<--- eat action should be here
+ return true;
//Makes moves towards target coordinates
if(xPosition==xTarget)
@@ -85,6 +89,7 @@ void Creature::Action()
yPosition--;
}
}
+ return false;
}
Location Creature::getLocation()