summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormajortom6 <tombarrett@siu.edu>2017-02-18 09:28:58 -0600
committermajortom6 <tombarrett@siu.edu>2017-02-18 09:28:58 -0600
commit03885192b9ff7d3c5e2dcfd98aefd21e9b62f603 (patch)
treec8bf20df1b634d2988e98de85c4439ca16620ca1
parent600ce4ae4179ddcb9849c6bb7646f8fc1e79c459 (diff)
general refractoring
-rw-r--r--inc/creature.hpp2
-rw-r--r--inc/entity.hpp26
-rw-r--r--inc/main.hpp3
-rw-r--r--inc/resource.hpp2
-rw-r--r--inc/window.hpp1
-rw-r--r--src/creature.cpp9
-rw-r--r--src/list.cpp17
-rw-r--r--src/main.cpp7
-rw-r--r--src/resource.cpp6
9 files changed, 32 insertions, 41 deletions
diff --git a/inc/creature.hpp b/inc/creature.hpp
index 56954fe..67617c6 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -19,7 +19,7 @@ class Creature: public Entity
void Priority();
void setTarget();
void checkTarget();
- void Move(SDL_Rect R);
+ void moveTowards(SDL_Rect R);
void impregnate(Dna D);
void giveN(std::vector<Entity*> n){N = n;};
diff --git a/inc/entity.hpp b/inc/entity.hpp
index 0eb8f60..1bb0405 100644
--- a/inc/entity.hpp
+++ b/inc/entity.hpp
@@ -7,22 +7,22 @@
class Entity
{
public:
- void Place();
-
- int getType(){return type;};
- SDL_Rect getRect(){return rect;};
+ void Place();
+
+ int getType(){return type;};
+ virtual bool getGender(void){};
+ virtual int getAmount(void){};
+ SDL_Rect getRect(){return rect;};
- virtual void eat(int bite){};
- virtual void impregnate(Dna D){};
- virtual bool getGender(void){};
- virtual int getAmount(void){};
+ virtual void eat(int bite){};
+ virtual void impregnate(Dna D){};
protected:
- int type;
- int gender;
- bool pregnate;
- SDL_Rect rect;
- SDL_Renderer* renderer;
+ int type;
+ int gender;
+ bool pregnate;
+ SDL_Rect rect;
+ SDL_Renderer* renderer;
};
#endif
diff --git a/inc/main.hpp b/inc/main.hpp
index 82a78c8..9dc5dcf 100644
--- a/inc/main.hpp
+++ b/inc/main.hpp
@@ -2,10 +2,7 @@
#define main_h
#include "window.hpp"
-#include "entity.hpp"
#include "event.hpp"
-#include "creature.hpp"
-#include "resource.hpp"
#include "list.hpp"
#include "timer.hpp"
diff --git a/inc/resource.hpp b/inc/resource.hpp
index cb5946c..89f6c45 100644
--- a/inc/resource.hpp
+++ b/inc/resource.hpp
@@ -7,7 +7,7 @@
class Resource: public Entity
{
public:
- Resource(Window m, SDL_Rect Rect);
+ Resource(Window m, SDL_Rect R);
int getAmount(){return amount;};
void grow();
void eat(int bite);
diff --git a/inc/window.hpp b/inc/window.hpp
index 8ce53db..d801972 100644
--- a/inc/window.hpp
+++ b/inc/window.hpp
@@ -2,7 +2,6 @@
#define window_h
#include <SDL2/SDL.h>
-#include <algorithm>
#include <string>
#include "constants.hpp"
diff --git a/src/creature.cpp b/src/creature.cpp
index dc5a307..bd731d2 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -16,7 +16,6 @@ Creature::Creature(Window M, SDL_Rect R, Dna D)
gender = rand() % 2;
age = 0;
pregnancyTime = 0;
- able = true;
pregnancyReady = false;
pregnate = false;
hasTarget = false;
@@ -88,7 +87,7 @@ void Creature::checkTarget()
for(std::vector <Entity*>::iterator it = N.begin(); it!=N.end(); it++)
if( target == *it )
return;
-
+
hasTarget = false;
}
@@ -112,17 +111,17 @@ void Creature::Action()
hasTarget = false;
}
else
- Move(target->getRect());
+ moveTowards(target->getRect());
}
else if(wander){
if(Distance(rect,wTarget) < mine.reach)
wander = false;
else
- Move(wTarget);
+ moveTowards(wTarget);
}
}
-void Creature::Move(SDL_Rect R)
+void Creature::moveTowards(SDL_Rect R)
{
if( rect.x == R.x ){
if( rect.y < R.y )
diff --git a/src/list.cpp b/src/list.cpp
index 68a71c9..afe51a3 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -17,7 +17,6 @@ List::List(Window m)
Resource Y(main,Rect);
R.push_back(Y);
}
-
}
void List::Remove()
@@ -44,9 +43,9 @@ void List::Behavior()
if(it->getPregnancyReady()){
Dna D = it->getChildDNA();
- SDL_Rect Rect = it->getRect();
- Rect.h = Rect.w = D.sizeMax / 5;
- Creature X(main,Rect,D);
+ SDL_Rect rect = it->getRect();
+ rect.h = rect.w = D.sizeMax / 5;
+ Creature X(main,rect,D);
C.push_back(X);
it->hadPregnancy();
}
@@ -58,9 +57,9 @@ void List::Behavior()
void List::Place()
{
- SDL_Rect Rect = {0,0,RESOURCE_SIZE_START,RESOURCE_SIZE_START};
+ SDL_Rect rect = {0,0,RESOURCE_SIZE_START,RESOURCE_SIZE_START};
while(R.size() < MINIMUM_RESOURCES){
- Resource Y(main,Rect);
+ Resource Y(main,rect);
R.push_back(Y);
}
@@ -76,13 +75,13 @@ std::vector<Entity*> List::getNear(Creature nC)
std::vector<Entity*> N;
for(std::list<Resource>::iterator it = R.begin(); it!=R.end(); it++)
- if( nC.getBestSense() > Distance(nC.getRect(),it->getRect()) )
+ if(nC.getBestSense() > Distance(nC.getRect(),it->getRect()))
N.push_back(&(*it));
for(std::list<Creature>::iterator it = C.begin(); it!=C.end(); it++)
- if( &nC == &(*it))
+ if(&nC == &(*it))
continue;
- else if( nC.getBestSense() > Distance(nC.getRect(),it->getRect()) )
+ else if(nC.getBestSense() > Distance(nC.getRect(),it->getRect()))
N.push_back(&(*it));
return N;
diff --git a/src/main.cpp b/src/main.cpp
index 82f0067..5170bf3 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -11,12 +11,9 @@ int main()
int speed = 60;
bool pause = false;
- while(e.gRun())
- {
+ while(e.gRun()){
fps.Start();
-
- while(e.Poll())
- {
+ while(e.Poll()){
if(e.gEventType() == SDL_QUIT)
e.off();
else if(e.gEventType() == SDL_KEYDOWN)
diff --git a/src/resource.cpp b/src/resource.cpp
index 2f2181f..ee9100a 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -1,9 +1,8 @@
#include "resource.hpp"
-Resource::Resource(Window m, SDL_Rect R)
+Resource::Resource(Window M, SDL_Rect R)
{
- renderer = m.getRenderer();
- type = RESOURCE_TYPE;
+ renderer = M.getRenderer();
rect = R;
if(rect.x == 0 && rect.y == 0){
@@ -11,6 +10,7 @@ Resource::Resource(Window m, SDL_Rect R)
rect.y = rand()%WINDOW_Y;
}
+ type = RESOURCE_TYPE;
amount = RESOURCE_AMOUNT_START;
growAmount = RESOURCE_GROW;
}