summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/creature.hpp3
-rw-r--r--src/creature.cpp23
-rw-r--r--src/list.cpp6
3 files changed, 22 insertions, 10 deletions
diff --git a/inc/creature.hpp b/inc/creature.hpp
index c3d5fdb..636d960 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -12,6 +12,7 @@ class Creature: public Entity
void Behavior();
void Action();
void Priority();
+ void setTarget();
void Move(Location l);
void giveN(list<Entity*> n){N = n;};
@@ -27,7 +28,7 @@ class Creature: public Entity
Location wTarget;
int health;
int maxHealth;
- int hunger;
+ bool hungry;
int speed = 1;
bool able;
int bestSense = 100;
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;
diff --git a/src/list.cpp b/src/list.cpp
index e44ad25..e08531b 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -4,14 +4,12 @@ List::List(Window m)
{
int i;
- for(i=0;i<10;i++)
- {
+ for(i=0;i<10;i++){
Creature X(m,"img/Cbasic.png");
C.push_back(X);
}
- for(i=0;i<100;i++)
- {
+ for(i=0;i<100;i++){
Resource Y(m,"img/Rbasic.png");
R.push_back(Y);
}