From 20717aeb1b12a7179e7b29c3c8880f18b360a1c8 Mon Sep 17 00:00:00 2001 From: tom Date: Fri, 13 May 2016 20:52:03 -0500 Subject: created settarget function and refractored priority --- src/creature.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/creature.cpp') 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 ::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; -- cgit v1.2.3