summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormajortom6 <tombarrett@siu.edu>2017-02-19 08:06:37 -0600
committerTom Barrett <tombarrett@siu.edu>2017-03-07 13:23:41 -0600
commit2cc21176467d4501adb7bfb9ee03eb9a2a7d14f2 (patch)
treee12ceac7024bdc697f1ed4adc1a1ece4a82489fc /src
parent74c6854fd8dcbaee736ac0421805ff1e03c4a1e2 (diff)
-removed all references to sdl_rect and location and now everything now uses our own class rectangle
-standardization of tab spaces to 8 is now in effect -refractoring of graphicsobjects.hpp
Diffstat (limited to 'src')
-rw-r--r--src/creature.cpp64
-rw-r--r--src/dna.cpp6
-rw-r--r--src/list.cpp15
-rw-r--r--src/main.cpp4
-rw-r--r--src/quadtree.cpp18
-rw-r--r--src/resource.cpp2
6 files changed, 54 insertions, 55 deletions
diff --git a/src/creature.cpp b/src/creature.cpp
index 0484fd1..7e5d0f3 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -1,9 +1,9 @@
#include "creature.hpp"
-Creature::Creature(Location t, Dna D)
+Creature::Creature(Rectangle t, DNA D)
{
L = t;
- mine = D;
+ myDNA = D;
if(L.x == 0 && L.y == 0){
L.x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30))));
@@ -15,7 +15,7 @@ Creature::Creature(Location t, Dna D)
gfxData.y = L.y;
type = CREATURE_TYPE;
- health = mine.maxHealth/2;
+ health = myDNA.maxHealth/2;
gender = rand() % 2;
age = 0;
pregnancyTime = 0;
@@ -55,18 +55,18 @@ void Creature::Behavior()
if(pregnate){
pregnancyTime++;
- if(pregnancyTime > mine.expectedPregnancyTime)
+ if(pregnancyTime > myDNA.expectedPregnancyTime)
pregnancyReady = true;
}
age++;
- if(age > mine.expectedAge)
+ if(age > myDNA.expectedAge)
health = 0;
}
void Creature::Priority()
{
- if(health < mine.maxHealth / 2){
+ if(health < myDNA.maxHealth / 2){
hungry = true;
able = false;
}
@@ -79,7 +79,7 @@ void Creature::Priority()
void Creature::setTarget()
{
//std::random_shuffle(N.begin(),N.end());
- for(std::list <Entity*>::iterator it = N.begin(); it!=N.end(); it++){
+ for(std::list <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++){
if( (*it)->getType() == RESOURCE_TYPE && hungry){
target = *it;
hasTarget = true;
@@ -98,7 +98,7 @@ void Creature::setTarget()
wander = true;
float x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30))));
float y = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30))));
- Location tmp;
+ Rectangle tmp;
tmp.x = x;
tmp.y = y;
wTarget = tmp;
@@ -107,7 +107,7 @@ void Creature::setTarget()
void Creature::checkTarget()
{
- for(std::list <Entity*>::iterator it = N.begin(); it!=N.end(); it++)
+ for(std::list <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++)
if( target == *it )
return;
@@ -118,73 +118,73 @@ void Creature::checkTarget()
void Creature::Action()
{
if(hasTarget){
- if( Distance(L,target->getLocation()) < mine.reach && target->getType() == RESOURCE_TYPE){
- target->eat(mine.bite);
- health+=mine.bite;
+ if( Distance(L,target->getRectangle()) < myDNA.reach && target->getType() == RESOURCE_TYPE){
+ target->eat(myDNA.bite);
+ health+=myDNA.bite;
amountAte++;
- //if(L.w <= mine.sizeMax && mine.amountToGrow <= amountAte){
+ //if(L.w <= myDNA.sizeMax && myDNA.amountToGrow <= amountAte){
// amountAte = 0;
// L.w = L.h = L.w + 1;
//}
if(target->getAmount()<=0)
hasTarget = false;
}
- else if( Distance(L,target->getLocation()) < mine.reach && target->getType() == CREATURE_TYPE && target->getGender() != gender ){
- target->impregnate(mine);
+ else if( Distance(L,target->getRectangle()) < myDNA.reach && target->getType() == CREATURE_TYPE && target->getGender() != gender ){
+ target->impregnate(myDNA);
hasTarget = false;
}
else
- moveTowards(target->getLocation());
+ moveTowards(target->getRectangle());
}
else if(wander){
- if(Distance(L,wTarget) < mine.reach)
+ if(Distance(L,wTarget) < myDNA.reach)
wander = false;
else
moveTowards(wTarget);
}
}
-void Creature::moveTowards(Location t)
+void Creature::moveTowards(Rectangle t)
{
if( L.x == t.x ){
if( L.y < t.y )
- L.y+=mine.speed;
+ L.y+=myDNA.speed;
else
- L.y-=mine.speed;
+ L.y-=myDNA.speed;
}
else if( L.y == t.y ){
if( L.x < t.x )
- L.x+=mine.speed;
+ L.x+=myDNA.speed;
else
- L.x-=mine.speed;
+ L.x-=myDNA.speed;
}
else if( L.x < t.x ){
if( L.y < t.y ){
- L.x+=mine.speed;
- L.y+=mine.speed;
+ L.x+=myDNA.speed;
+ L.y+=myDNA.speed;
}
else{
- L.x+=mine.speed;
- L.y-=mine.speed;
+ L.x+=myDNA.speed;
+ L.y-=myDNA.speed;
}
}
else if ( L.x > t.x ){
if( L.y < t.y ){
- L.x-=mine.speed;
- L.y+=mine.speed;
+ L.x-=myDNA.speed;
+ L.y+=myDNA.speed;
}
else{
- L.x-=mine.speed;
- L.y-=mine.speed;
+ L.x-=myDNA.speed;
+ L.y-=myDNA.speed;
}
}
}
-void Creature::impregnate(Dna D)
+void Creature::impregnate(DNA D)
{
if(!pregnate){
pregnate = true;
pregnancyTime = 0;
- childs = mine.combine(D);
+ childsDNA = myDNA.combine(D);
}
}
diff --git a/src/dna.cpp b/src/dna.cpp
index 1145276..bc51fd9 100644
--- a/src/dna.cpp
+++ b/src/dna.cpp
@@ -1,6 +1,6 @@
#include "dna.hpp"
-Dna::Dna()
+DNA::DNA()
{
maxHealth = CREATURE_MAX_HEALTH;
speed = CREATURE_SPEED;
@@ -13,9 +13,9 @@ Dna::Dna()
sizeMax = CREATURE_SIZE_MAX;
}
-Dna Dna::combine(Dna D)
+DNA DNA::combine(DNA D)
{
- Dna N;
+ DNA N;
N.maxHealth = (this->maxHealth + D.maxHealth)/2;
N.speed = (this->speed + D.speed)/2;
diff --git a/src/list.cpp b/src/list.cpp
index fab5813..e83822f 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -3,9 +3,8 @@
List::List()
{
int i;
- Dna defaultDNA;
- //SDL_Rect rect = {0,0,defaultDNA.sizeMax/5,defaultDNA.sizeMax/5};
- Location tmp;
+ DNA defaultDNA;
+ Rectangle tmp;
tmp.x = tmp.y = 0;
for(i=0;i<CREATURES;i++){
Creature X(tmp,defaultDNA);
@@ -26,7 +25,7 @@ void List::Remove()
{
for(std::list<Creature>::iterator it = C.begin(); it!=C.end(); it++)
if(it->getHealth()<=0){
- Location tmp = it->getLocation();
+ Rectangle tmp = it->getRectangle();
Resource r = Resource(tmp);
R.push_back(r);
C.erase(it--);
@@ -41,12 +40,12 @@ void List::Behavior()
{
for(std::list<Creature>::iterator it = C.begin(); it!=C.end(); it++){
std::list<Entity*> N = getNear(*it);
- it->giveN(N);
+ it->giveNearMe(N);
it->Behavior();
if(it->getPregnancyReady()){
- Dna D = it->getChildDNA();
- Location tmp = it->getLocation();
+ DNA D = it->getChildsDNA();
+ Rectangle tmp = it->getRectangle();
Creature X(tmp,D);
C.push_back(X);
it->hadPregnancy();
@@ -61,7 +60,7 @@ void List::Place()
{
tree.clear();
- Location tmp;
+ Rectangle tmp;
tmp.x = tmp.y = 0;
while(R.size() < MINIMUM_RESOURCES){
Resource Y(tmp);
diff --git a/src/main.cpp b/src/main.cpp
index e385f9f..eb4438f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -55,10 +55,10 @@ int main()
shader.Bind();
_spriteBatch.begin();
for(std::list<Creature>::iterator it = L.C.begin(); it != L.C.end(); it++)
- _spriteBatch.draw(it->gfxData);;
+ _spriteBatch.draw(it->getGFXD());;
for(std::list<Resource>::iterator it = L.R.begin(); it != L.R.end(); it++)
- _spriteBatch.draw(it->gfxData);;
+ _spriteBatch.draw(it->getGFXD());;
_spriteBatch.end();
_spriteBatch.renderBatch();
diff --git a/src/quadtree.cpp b/src/quadtree.cpp
index e347e55..9fd4f0c 100644
--- a/src/quadtree.cpp
+++ b/src/quadtree.cpp
@@ -13,7 +13,7 @@ Quadtree::Quadtree(int pLevel, Rectangle pBounds){
gfxDataRect.r = 255;
gfxDataRect.g = 0;
gfxDataRect.b = 255;
- gfxDataRect.sides = pBounds.height;
+ gfxDataRect.sides = pBounds.h;
}
void Quadtree::clear(){
@@ -31,10 +31,10 @@ void Quadtree::clear(){
}
void Quadtree::split(){
- float subWidth = (bounds.getWidth() / 2);
- float subHeight = (bounds.getHeight() / 2);
- float x = bounds.getX();
- float y = bounds.getY();
+ float subWidth = (bounds.w / 2);
+ float subHeight = (bounds.h / 2);
+ float x = bounds.x;
+ float y = bounds.y;
Rectangle R0(x + subWidth/2, y + subHeight/2, subWidth, subHeight);
@@ -57,16 +57,16 @@ void Quadtree::clear(){
int Quadtree::getIndex(GraphicsData object) {
int index = -1;
- bool topQuadrant = (object.getY() > bounds.getY());
- bool bottomQuadrant = (object.getY() < bounds.getY());
+ bool topQuadrant = (object.y > bounds.y);
+ bool bottomQuadrant = (object.y < bounds.y);
- if (object.getX() < bounds.getX()) {
+ if (object.x < bounds.x) {
if (topQuadrant)
index = 1;
else if (bottomQuadrant)
index = 2;
}
- else if (object.getX() > bounds.getX()) {
+ else if (object.x > bounds.x) {
if (topQuadrant)
index = 0;
else if (bottomQuadrant)
diff --git a/src/resource.cpp b/src/resource.cpp
index 31811ca..fdb4bf0 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -1,6 +1,6 @@
#include "resource.hpp"
-Resource::Resource(Location t)
+Resource::Resource(Rectangle t)
{
L = t;