summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--inc/creature.hpp5
-rw-r--r--src/creature.cpp69
-rw-r--r--src/list.cpp2
3 files changed, 39 insertions, 37 deletions
diff --git a/inc/creature.hpp b/inc/creature.hpp
index 7da82e5..c3d5fdb 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -12,8 +12,9 @@ class Creature: public Entity
void Behavior();
void Action();
void Priority();
+ void Move(Location l);
void giveN(list<Entity*> n){N = n;};
-
+
Location getLocation(){return L;};
double Distance(Location A, Location B){return sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2));};
int getHealth(){return health;};
@@ -22,6 +23,8 @@ class Creature: public Entity
private:
bool hasTarget;
+ bool wander;
+ Location wTarget;
int health;
int maxHealth;
int hunger;
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.y<target->getLocation().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.x<target->getLocation().x)
+ else if( L.y == l.y ){
+ if( L.x < l.x )
L.x+=speed;
else
L.x-=speed;
}
-
- else if(L.x<target->getLocation().x)
- {
- if(L.y<target->getLocation().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.y<target->getLocation().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;
}
- }
+ }
}
diff --git a/src/list.cpp b/src/list.cpp
index 5d8ae35..e44ad25 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -4,7 +4,7 @@ List::List(Window m)
{
int i;
- for(i=0;i<2;i++)
+ for(i=0;i<10;i++)
{
Creature X(m,"img/Cbasic.png");
C.push_back(X);