summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-05-08 08:23:06 -0500
committertom <tom@ground-control>2015-05-08 08:23:06 -0500
commit8c5121486a0e5d94ae5e5ee67370a31530cf8b6f (patch)
treef1e82b3dbd17485613e1100290f263426751db03
parent04069434be15c06666a7493b1b6329a78c00d1d1 (diff)
fixed some comments and cleaned around
-rw-r--r--inc/creature.hpp2
-rw-r--r--inc/list.hpp1
-rw-r--r--src/creature.cpp13
-rw-r--r--src/list.cpp3
-rw-r--r--src/resource.cpp2
5 files changed, 8 insertions, 13 deletions
diff --git a/inc/creature.hpp b/inc/creature.hpp
index 9a26ee8..9bb73ee 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -19,7 +19,7 @@ class Creature: public Entity
int yTarget; //y-coordinate of creature's target position
int health; //health of a creature (0-100)
int hunger; //value associated with a creatures want to find food (0-100)
- std::vector<Location> location; //vector containing creatures location on window or target location?
+ std::vector<Location> location; //vector containing objects near the creature
};
#endif
diff --git a/inc/list.hpp b/inc/list.hpp
index 074e045..dc5c412 100644
--- a/inc/list.hpp
+++ b/inc/list.hpp
@@ -16,6 +16,7 @@ class List
private:
//vectors containing objects of each type
+ Window * main;//will be needed for adding R's and C's after constructor.
std::vector<Resource> R;
std::vector<Creature> C;
std::vector<Location> L;
diff --git a/src/creature.cpp b/src/creature.cpp
index ef3d6c1..5c3bb8e 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -8,16 +8,13 @@ Creature::Creature(Window m, std::string s) //Constructor
hunger = 0;
//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;
+ yPosition=yTarget=rand()%800;
+ xPosition=xTarget=rand()%1200;
}
void Creature::Behavior()
{
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
}
@@ -28,19 +25,17 @@ void Creature::Priority()
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()
{
- //If the distance is too small, do something?
+ //If the distance is close, will return an bool
if(sqrt(pow(xPosition - xTarget, 2) + pow(yPosition - yTarget, 2)) < 2)
return; //<--- eat action should be here
@@ -94,7 +89,7 @@ void Creature::Action()
Location Creature::getLocation()
{
- //returns location vector of creatures position coordinates
+ //returns location object of the specific creature
Location L(xPosition, yPosition, 1);
return L;
}
diff --git a/src/list.cpp b/src/list.cpp
index b86f077..2140a75 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -65,6 +65,5 @@ void List::Behavior()
double List::Distance(Location A, Location B)
{
//computes distance between two points
- double z = sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2));
- return z;
+ return sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2));
}
diff --git a/src/resource.cpp b/src/resource.cpp
index c4a9341..5044760 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -12,7 +12,7 @@ Resource::Resource(Window m, std::string s) //Constructor
xPosition = xStart;
}
-Location Resource::getLocation() //Returns resource location vector
+Location Resource::getLocation() //Returns resource object
{
Location L(xPosition,yPosition,2);
return L;