summaryrefslogtreecommitdiff
path: root/src/creature.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/creature.cpp')
-rw-r--r--src/creature.cpp131
1 files changed, 56 insertions, 75 deletions
diff --git a/src/creature.cpp b/src/creature.cpp
index ae3122b..ef3d6c1 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -1,119 +1,100 @@
#include "creature.hpp"
-Creature::Creature(Window m, std::string s)
+Creature::Creature(Window m, std::string s) //Constructor
{
texture = loadTexture(s, m);
renderer = m.getRenderer();
- hp = 100;
- hu = 0;
+ health = 100;
+ hunger = 0;
- int zy = rand()%800;
- int zx = rand()%1200;
- y=yT=zy;
- x=xT=zx;
- //std::cout << x << ' ' << y << std::endl;
-
- //For the test resource
- //xT=yT=300;
+ //initializes random start coordinates for creature, target position is equivalent to it's position
+ int yStart = rand()%800;
+ int xStart = rand()%1200;
+ yPosition=yTarget=yStart;
+ xPosition=xTarget=xStart;
}
void Creature::Behavior()
{
- hp--;
+ health--; //Decrements health each time a behavior is executed
//Detection
+ this->Priority(); //Checks which action has priority (doesn't really do this right now)
+ this->Action(); //Does action
+}
- //Priorities
- this->Priority();
- //Action
- this->Action();
+void Creature::Priority()
+{
+ //Traverses location vector, if object at [i] is resource (2), then creature's target coordinates are set
+ int i;
+ for(i=0;i<location.size();i++)
+ {
+ std::cout << location[i].type;
+ if(location[i].type==2)
+ {
+ xTarget = location[i].x;
+ yTarget = location[i].y;
+ std::cout << xTarget << "IN\n";
+ }
+ }
}
void Creature::Action()
{
- //std::cout << (sqrt(((x-xT)^2)+((y-yT)^2));
- if(sqrt(pow(x-xT,2)+pow(y-yT,2))<2)
- return; //eat//reproduce//etc;
+ //If the distance is too small, do something?
+ if(sqrt(pow(xPosition - xTarget, 2) + pow(yPosition - yTarget, 2)) < 2)
+ return; //<--- eat action should be here
- if(x==xT)
+ //Makes moves towards target coordinates
+ if(xPosition==xTarget)
{
- if(y<yT)
- y++;
+ if(yPosition<yTarget)
+ yPosition++;
else
- y--;
+ yPosition--;
}
- else if(y==yT)
+
+ else if(yPosition==yTarget)
{
- if(x<xT)
- x++;
+ if(xPosition<xTarget)
+ xPosition++;
else
- x--;
+ xPosition--;
}
- else if(x<xT)
- {
- if(y<yT)
- {
- x++;
- y++;
- }
- else
- {
- x++;
- y--;
- }
- }
- else if (x>xT)
+
+ else if(xPosition<xTarget)
{
- if(y<yT)
+ if(yPosition<yTarget)
{
- x--;
- y++;
+ xPosition++;
+ yPosition++;
}
+
else
{
- x--;
- y--;
+ xPosition++;
+ yPosition--;
}
}
- /*
- else
+ else if (xPosition>xTarget)
{
- int z = rand()%2;
- if(z)
- {
- if(x<xT)
- x++;
- else
- x--;
- }
- else
+ if(yPosition<yTarget)
{
- if(y<yT)
- y++;
- else
- y--;
+ xPosition--;
+ yPosition++;
}
- }
- */
-}
-void Creature::Priority()
-{
- int i;
- for(i=0;i<K.size();i++)
- {
- std::cout << K[i].t;
- if(K[i].t==2)
+ else
{
- xT = K[i].x;
- yT = K[i].y;
- std::cout << xT << "IN\n";
+ xPosition--;
+ yPosition--;
}
}
}
Location Creature::getLocation()
{
- Location L(x,y,1);
+ //returns location vector of creatures position coordinates
+ Location L(xPosition, yPosition, 1);
return L;
}