summaryrefslogtreecommitdiff
path: root/src/creature.cpp
diff options
context:
space:
mode:
authortom <tom@ground-control>2016-05-13 20:52:03 -0500
committertom <tom@ground-control>2016-05-13 20:52:03 -0500
commit20717aeb1b12a7179e7b29c3c8880f18b360a1c8 (patch)
treef9f3ea119f03a276a0f241d0c1c10b01a3c44690 /src/creature.cpp
parent05c98dad6bca7f0bcae2a09a12f4863dac546e22 (diff)
created settarget function and refractored priority
Diffstat (limited to 'src/creature.cpp')
-rw-r--r--src/creature.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/creature.cpp b/src/creature.cpp
index cc7fb3e..ead0b2d 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -6,12 +6,12 @@ Creature::Creature(Window m, std::string s)
renderer = m.getRenderer();
health = 500;
maxHealth = 1000;
- hunger = 0;
L.y=rand()%800;
L.x=rand()%1200;
type = 1;
+ hungry = false;
hasTarget = false;
wander = false;
able = true;
@@ -23,13 +23,27 @@ void Creature::Behavior()
this->Priority();
+ this->setTarget();
+
this->Action();
}
void Creature::Priority()
{
+ if(health < maxHealth/2){
+ hungry = true;
+ able = false;
+ }
+ else{
+ hungry = false;
+ able = true;
+ }
+}
+
+void Creature::setTarget()
+{
for(list <Entity*>::iterator it = N.begin(); it!=N.end(); it++){
- if((*it)->getType() == 2){
+ if((*it)->getType() == 2 && hungry){
if(!hasTarget){
target = *it;
hasTarget = true;
@@ -44,10 +58,9 @@ void Creature::Priority()
wander = true;
wTarget = Location(rand()%1200,rand()%800);
}
-
-
}
+
void Creature::Action()
{
if(hasTarget){
@@ -73,7 +86,7 @@ void Creature::Action()
void Creature::Move(Location l)
{
if( L.x == l.x ){
- if( L.y < l.y )
+ if( L.y < l.y )
L.y+=speed;
else
L.y-=speed;