#include "creature.hpp" Creature::Creature(Window m, std::string s) //Constructor { texture = loadTexture(s, m); renderer = m.getRenderer(); health = 100; hunger = 0; //initializes random start coordinates for creature, target position is equivalent to it's position yPosition=yTarget=rand()%800; xPosition=xTarget=rand()%1200; hasTarget = false; n=0; } int Creature::Behavior() { health-=1; //Decrements health each time a behavior is executed this->Priority(); if(this->Action()) { if(nR.size()) { nR[n]->eat(); if(health<500) health+=10; } } return 0; } void Creature::Priority() { double d; // lol for(int i = 0; i < nR.size(); i++) { if(!i) d = Distance(this->getLocation(),nR[0]->getLocation()); if(d>Distance(this->getLocation(),nR[i]->getLocation())) { d=Distance(this->getLocation(),nR[i]->getLocation()); n=i; } } if(nR.size()) { xTarget = nR[n]->getLocation().x; yTarget = nR[n]->getLocation().y; hasTarget = true; } else hasTarget = false; } bool Creature::Action() { //If the distance is close, will return an bool //if(xPosition == xTarget && yPosition == yTarget) // return false; if(nR.size()) if(5 > Distance(this->getLocation(),nR[n]->getLocation())) { if(hasTarget) return true; else return false; } //Makes moves towards target coordinates if(xPosition==xTarget) { if(yPositionxTarget) { if(yPosition