From ffcee12acf3fe3f972f322c18b3203212682205d Mon Sep 17 00:00:00 2001 From: tom Date: Thu, 7 May 2015 12:35:15 -0500 Subject: woo! detection is implemented albeit shitty --- src/creature.cpp | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'src/creature.cpp') diff --git a/src/creature.cpp b/src/creature.cpp index 9d50291..ae3122b 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -9,30 +9,29 @@ Creature::Creature(Window m, std::string s) int zy = rand()%800; int zx = rand()%1200; - y=zy; - x=zx; + y=yT=zy; + x=xT=zx; //std::cout << x << ' ' << y << std::endl; - + //For the test resource - xT=yT=300; + //xT=yT=300; } void Creature::Behavior() { hp--; - //Detection - - - //Priorities + //Detection - //Action - this->Action(); + //Priorities + this->Priority(); + //Action + this->Action(); } void Creature::Action() { //std::cout << (sqrt(((x-xT)^2)+((y-yT)^2)); - if((sqrt(((x-xT)^2)+((y-yT)^2)))<2) + if(sqrt(pow(x-xT,2)+pow(y-yT,2))<2) return; //eat//reproduce//etc; if(x==xT) @@ -76,7 +75,7 @@ void Creature::Action() } } - /* + /* else { int z = rand()%2; @@ -98,6 +97,21 @@ void Creature::Action() */ } +void Creature::Priority() +{ + int i; + for(i=0;i Date: Thu, 7 May 2015 19:53:39 -0500 Subject: Some variable names changed and many comments made so I understand what the fuck is going on --- src/creature.cpp | 131 ++++++++++++++++++++++++------------------------------- 1 file changed, 56 insertions(+), 75 deletions(-) (limited to 'src/creature.cpp') 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;ixT) + + else if(xPositionxTarget) { - int z = rand()%2; - if(z) - { - if(x Date: Fri, 8 May 2015 08:23:06 -0500 Subject: fixed some comments and cleaned around --- src/creature.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/creature.cpp') 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