diff options
author | majortom6 <tombarrett@siu.edu> | 2017-02-19 10:41:00 -0600 |
---|---|---|
committer | Tom Barrett <tombarrett@siu.edu> | 2017-03-07 13:23:41 -0600 |
commit | fcf6abaccec7c7ed2fd306a9cf1ec378f303297c (patch) | |
tree | 75d4df2b09346014e4784c2b597f0110a6b82e5b /src | |
parent | 5c46e0f0a924989201c6784b0f956bc442f14a7e (diff) |
-refractoring of includes
Diffstat (limited to 'src')
-rw-r--r-- | src/creature.cpp | 62 | ||||
-rw-r--r-- | src/entity.cpp | 4 | ||||
-rw-r--r-- | src/list.cpp | 32 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rw-r--r-- | src/quadtree.cpp | 2 | ||||
-rw-r--r-- | src/resource.cpp | 14 |
6 files changed, 59 insertions, 59 deletions
diff --git a/src/creature.cpp b/src/creature.cpp index 7e5d0f3..9f8204b 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -2,17 +2,17 @@ Creature::Creature(Rectangle t, DNA D) { - L = t; + rect = t; myDNA = D; - if(L.x == 0 && L.y == 0){ - L.x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); - L.y = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); + if(rect.x == 0 && rect.y == 0){ + rect.x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); + rect.y = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); } gfxData.sides = 4.0; - gfxData.x = L.x; - gfxData.y = L.y; + gfxData.x = rect.x; + gfxData.y = rect.y; type = CREATURE_TYPE; health = myDNA.maxHealth/2; @@ -118,18 +118,18 @@ void Creature::checkTarget() void Creature::Action() { if(hasTarget){ - if( Distance(L,target->getRectangle()) < myDNA.reach && target->getType() == RESOURCE_TYPE){ + if( Distance(rect,target->getRectangle()) < myDNA.reach && target->getType() == RESOURCE_TYPE){ target->eat(myDNA.bite); health+=myDNA.bite; amountAte++; - //if(L.w <= myDNA.sizeMax && myDNA.amountToGrow <= amountAte){ + //if(rect.w <= myDNA.sizeMax && myDNA.amountToGrow <= amountAte){ // amountAte = 0; - // L.w = L.h = L.w + 1; + // rect.w = rect.h = rect.w + 1; //} if(target->getAmount()<=0) hasTarget = false; } - else if( Distance(L,target->getRectangle()) < myDNA.reach && target->getType() == CREATURE_TYPE && target->getGender() != gender ){ + else if( Distance(rect,target->getRectangle()) < myDNA.reach && target->getType() == CREATURE_TYPE && target->getGender() != gender ){ target->impregnate(myDNA); hasTarget = false; } @@ -137,7 +137,7 @@ void Creature::Action() moveTowards(target->getRectangle()); } else if(wander){ - if(Distance(L,wTarget) < myDNA.reach) + if(Distance(rect,wTarget) < myDNA.reach) wander = false; else moveTowards(wTarget); @@ -146,36 +146,36 @@ void Creature::Action() void Creature::moveTowards(Rectangle t) { - if( L.x == t.x ){ - if( L.y < t.y ) - L.y+=myDNA.speed; + if( rect.x == t.x ){ + if( rect.y < t.y ) + rect.y+=myDNA.speed; else - L.y-=myDNA.speed; + rect.y-=myDNA.speed; } - else if( L.y == t.y ){ - if( L.x < t.x ) - L.x+=myDNA.speed; + else if( rect.y == t.y ){ + if( rect.x < t.x ) + rect.x+=myDNA.speed; else - L.x-=myDNA.speed; + rect.x-=myDNA.speed; } - else if( L.x < t.x ){ - if( L.y < t.y ){ - L.x+=myDNA.speed; - L.y+=myDNA.speed; + else if( rect.x < t.x ){ + if( rect.y < t.y ){ + rect.x+=myDNA.speed; + rect.y+=myDNA.speed; } else{ - L.x+=myDNA.speed; - L.y-=myDNA.speed; + rect.x+=myDNA.speed; + rect.y-=myDNA.speed; } } - else if ( L.x > t.x ){ - if( L.y < t.y ){ - L.x-=myDNA.speed; - L.y+=myDNA.speed; + else if ( rect.x > t.x ){ + if( rect.y < t.y ){ + rect.x-=myDNA.speed; + rect.y+=myDNA.speed; } else{ - L.x-=myDNA.speed; - L.y-=myDNA.speed; + rect.x-=myDNA.speed; + rect.y-=myDNA.speed; } } } diff --git a/src/entity.cpp b/src/entity.cpp index 13bd290..ab94d23 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -2,6 +2,6 @@ void Entity::Place() { - gfxData.x = L.x; - gfxData.y = L.y; + gfxData.x = rect.x; + gfxData.y = rect.y; } diff --git a/src/list.cpp b/src/list.cpp index e83822f..71c0ba9 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -8,37 +8,37 @@ List::List() tmp.x = tmp.y = 0; for(i=0;i<CREATURES;i++){ Creature X(tmp,defaultDNA); - C.push_back(X); + creatures.push_back(X); } //rect = {0,0,RESOURCE_SIZE_START,RESOURCE_SIZE_START}; for(i=0;i<RESOURCES;i++){ Resource Y(tmp); - R.push_back(Y); + resources.push_back(Y); } - R1 = Rectangle(0,0,60,60); - tree = Quadtree(0,R1); + Rectangle R1 = Rectangle(0,0,60,60); + tree = Quadtree(0, R1); } void List::Remove() { - for(std::list<Creature>::iterator it = C.begin(); it!=C.end(); it++) + for(std::list<Creature>::iterator it = creatures.begin(); it!= creatures.end(); it++) if(it->getHealth()<=0){ Rectangle tmp = it->getRectangle(); Resource r = Resource(tmp); - R.push_back(r); - C.erase(it--); + resources.push_back(r); + creatures.erase(it--); } - for(std::list<Resource>::iterator it = R.begin(); it!=R.end(); it++) + for(std::list<Resource>::iterator it = resources.begin(); it!= resources.end(); it++) if(it->getAmount()<=0) - R.erase(it--); + resources.erase(it--); } void List::Behavior() { - for(std::list<Creature>::iterator it = C.begin(); it!=C.end(); it++){ + for(std::list<Creature>::iterator it = creatures.begin(); it!= creatures.end(); it++){ std::list<Entity*> N = getNear(*it); it->giveNearMe(N); it->Behavior(); @@ -47,12 +47,12 @@ void List::Behavior() DNA D = it->getChildsDNA(); Rectangle tmp = it->getRectangle(); Creature X(tmp,D); - C.push_back(X); + creatures.push_back(X); it->hadPregnancy(); } } - for(std::list<Resource>::iterator it = R.begin(); it!=R.end(); it++) + for(std::list<Resource>::iterator it = resources.begin(); it!= resources.end(); it++) it->grow(); } @@ -62,17 +62,17 @@ void List::Place() Rectangle tmp; tmp.x = tmp.y = 0; - while(R.size() < MINIMUM_RESOURCES){ + while(resources.size() < MINIMUM_RESOURCES){ Resource Y(tmp); - R.push_back(Y); + resources.push_back(Y); } - for(std::list<Creature>::iterator it = C.begin(); it!=C.end(); it++){ + for(std::list<Creature>::iterator it = creatures.begin(); it!= creatures.end(); it++){ it->Place(); tree.insert(&(*it));; } - for(std::list<Resource>::iterator it = R.begin(); it!=R.end(); it++){ + for(std::list<Resource>::iterator it = resources.begin(); it!=resources.end(); it++){ it->Place(); tree.insert(&(*it));; } diff --git a/src/main.cpp b/src/main.cpp index c7ce9e7..1033651 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,10 +54,10 @@ int main() shader.Bind();
_spriteBatch.begin();
- for(std::list<Creature>::iterator it = L.C.begin(); it != L.C.end(); it++)
+ for(std::list<Creature>::iterator it = L.creatures.begin(); it != L.creatures.end(); it++)
_spriteBatch.draw(it->getGFXD());;
- for(std::list<Resource>::iterator it = L.R.begin(); it != L.R.end(); it++)
+ for(std::list<Resource>::iterator it = L.resources.begin(); it != L.resources.end(); it++)
_spriteBatch.draw(it->getGFXD());;
_spriteBatch.end();
diff --git a/src/quadtree.cpp b/src/quadtree.cpp index 9fd4f0c..91cddf5 100644 --- a/src/quadtree.cpp +++ b/src/quadtree.cpp @@ -3,7 +3,7 @@ Quadtree::Quadtree(){}
-Quadtree::Quadtree(int pLevel, Rectangle pBounds){
+Quadtree::Quadtree(int pLevel,Rectangle pBounds){
level = pLevel;
bounds = pBounds;
isNull=false;
diff --git a/src/resource.cpp b/src/resource.cpp index fdb4bf0..9933c4f 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -2,15 +2,15 @@ Resource::Resource(Rectangle t) { - L = t; + rect = t; - if(L.x == 0 && L.y == 0){ - L.x = -30 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30.0-(-30.0)))); - L.y = -30 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30.0-(-30.0)))); + if(rect.x == 0 && rect.y == 0){ + rect.x = -30 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30.0-(-30.0)))); + rect.y = -30 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30.0-(-30.0)))); } - gfxData.x = L.x; - gfxData.y = L.y; + gfxData.x = rect.x; + gfxData.y = rect.y; gfxData.r = 0.0; gfxData.g = 1.0; gfxData.b = 0.0; @@ -30,6 +30,6 @@ void Resource::grow() { if(amount < RESOURCE_AMOUNT_MAX){ amount+=growAmount; - L.h = L.w = map(amount,0,RESOURCE_AMOUNT_MAX,0,RESOURCE_SIZE_MAX); + rect.h = rect.w = map(amount,0,RESOURCE_AMOUNT_MAX,0,RESOURCE_SIZE_MAX); } } |