From 6873831fa5c99f74609c60e2918692cdd46f1aa1 Mon Sep 17 00:00:00 2001 From: tom Date: Mon, 2 May 2016 22:31:59 -0500 Subject: reimplemented wandering --- src/creature.cpp | 69 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 34 insertions(+), 35 deletions(-) (limited to 'src/creature.cpp') diff --git a/src/creature.cpp b/src/creature.cpp index 3ae02ce..3b26f63 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -13,7 +13,8 @@ Creature::Creature(Window m, std::string s) type = 1; hasTarget = false; - able = true; + wander = false; + able = true; } void Creature::Behavior() @@ -32,73 +33,71 @@ void Creature::Priority() if(!hasTarget){ target = *it; hasTarget = true; + wander = false; } else break; } } + + if(!hasTarget&&!wander){ + wander = true; + wTarget = Location(rand()%1200,rand()%800); + } + + } void Creature::Action() { - //cout << "My coords:" << L.x << "," << L.y << endl; - cout << "Mytcoords:" << target->getLocation().x << "," << target->getLocation().y << endl << endl; - if(hasTarget){ if(Distance(L,target->getLocation())<5){ target->eat(); - health+=1000; + health+=10; } - if(target->getAmount()==0){ - hasTarget = false; - cout << "done\n"; + else + Move(target->getLocation()); + + if(target->getAmount()<=0){ + hasTarget = false; } - } + } + else + Move(wTarget); +} - //Makes moves towards target coordinates - if(L.x==target->getLocation().x) - { - if(L.ygetLocation().y) - L.y+=speed; +void Creature::Move(Location l) +{ + if( L.x == l.x ){ + if( L.y < l.y ) + L.y+=speed; else L.y-=speed; } - - else if(L.y==target->getLocation().y) - { - if(L.xgetLocation().x) + else if( L.y == l.y ){ + if( L.x < l.x ) L.x+=speed; else L.x-=speed; } - - else if(L.xgetLocation().x) - { - if(L.ygetLocation().y) - { + else if( L.x < l.x ){ + if( L.y < l.y ){ L.x+=speed; L.y+=speed; } - - else - { + else{ L.x+=speed; L.y-=speed; } } - - else if (L.x>target->getLocation().x) - { - if(L.ygetLocation().y) - { + else if ( L.x > l.x ){ + if( L.y < l.y ){ L.x-=speed; L.y+=speed; } - - else - { + else{ L.x-=speed; L.y-=speed; } - } + } } -- cgit v1.2.3