summaryrefslogtreecommitdiff
path: root/inc
diff options
context:
space:
mode:
authortom <tombarrett@siu.edu>2017-01-21 08:58:12 -0600
committertom <tombarrett@siu.edu>2017-01-21 08:58:12 -0600
commita9281bfcf21861e621a3243ecb633a299c8d8e52 (patch)
tree7d4687fd9a8f40e806e6b7c8803c0e87fcae6639 /inc
parentccb66c8d6d175b1bd3d8ecaa540e80baac5181b6 (diff)
-took basic math functions and put it into functions.hpp
-spaced various lines -reorganized variables by datatype -implemented reproduction -reorganized pathing so once a target is set, the creature checks if that same target is near every cycle
Diffstat (limited to 'inc')
-rw-r--r--inc/constants.hpp43
-rw-r--r--inc/creature.hpp39
-rw-r--r--inc/entity.hpp6
-rw-r--r--inc/functions.hpp12
-rw-r--r--inc/list.hpp2
-rw-r--r--inc/resource.hpp5
-rw-r--r--inc/timer.hpp2
7 files changed, 65 insertions, 44 deletions
diff --git a/inc/constants.hpp b/inc/constants.hpp
index 8496e5c..fd00fb1 100644
--- a/inc/constants.hpp
+++ b/inc/constants.hpp
@@ -1,29 +1,30 @@
#ifndef constants_h
#define constants_h
-const int CREATURES = 100;
-const int RESOURCES = 1000;
-const int MINIMUM_RESOURCES = 700;
-const int WINDOW_X = 1080;
-const int WINDOW_Y = 640;
+const int CREATURES = 10;
+const int RESOURCES = 100;
+const int MINIMUM_RESOURCES = 70;
+const int WINDOW_X = 500;
+const int WINDOW_Y = 500;
-const int CREATURE_TYPE = 1;
-const int RESOURCE_TYPE = 2;
+const int CREATURE_TYPE = 1;
+const int RESOURCE_TYPE = 2;
-const int CREATURE_START_HEALTH = 500;
-const int CREATURE_MAX_HEALTH = 1000;
-const int CREATURE_BEST_SENSE = 100;
-const int CREATURE_SPEED = 1;
-const int CREATURE_REACH = 5;
-const int CREATURE_SIZE_MAX = 5;
-const int CREATURE_SIZE_START = 1;
-const int CREATURE_BITE = 10;
-const int CREATURE_AMOUNT_TO_GROW = 50;
+const int CREATURE_START_HEALTH = 500;
+const int CREATURE_MAX_HEALTH = 1000;
+const int CREATURE_BEST_SENSE = 100;
+const int CREATURE_SPEED = 1;
+const int CREATURE_REACH = 5;
+const int CREATURE_SIZE_MAX = 10;
+const int CREATURE_SIZE_START = 5;
+const int CREATURE_BITE = 10;
+const int CREATURE_AMOUNT_TO_GROW = 50;
+const int CREATURE_EXPECTED_PREGNANCY_TIME = 100;
-const int RESOURCE_SIZE_START = 5;
-const int RESOURCE_SIZE_MAX = 2;
-const int RESOURCE_AMOUNT_START = 100;
-const int RESOURCE_AMOUNT_MAX = 200;
-const int RESOURCE_GROW = 1;
+const int RESOURCE_SIZE_START = 1;
+const int RESOURCE_SIZE_MAX = 4;
+const int RESOURCE_AMOUNT_START = 100;
+const int RESOURCE_AMOUNT_MAX = 200;
+const int RESOURCE_GROW = 1;
#endif
diff --git a/inc/creature.hpp b/inc/creature.hpp
index edc253f..79ec4c3 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -6,28 +6,32 @@
#include "entity.hpp"
#include "constants.hpp"
+#include "functions.hpp"
class Creature: public Entity
{
public:
Creature(Window m, SDL_Rect R);
- void Behavior();
- void Action();
- void Priority();
- void setTarget();
- void Move(SDL_Rect R);
-
+ void Behavior();
+ void Action();
+ void Priority();
+ void setTarget();
+ void checkTarget();
+ void Move(SDL_Rect R);
+ void impregnate();
void giveN(list<Entity*> n){N = n;};
- double Distance(SDL_Rect A, SDL_Rect B){return sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2));};
+
int getHealth(){return health;};
- bool doesItHaveTarget(){return hasTarget;};
int getBestSense(){return bestSense;};
-
+ bool getGender(){return gender;};
+ bool getPregnancyReady(){return pregnancyReady;};
+ void hadPregnancy(){pregnate = pregnancyReady = false;};
+
private:
- bool hasTarget;
- bool wander;
- SDL_Rect wTarget;
-
+ SDL_Rect wTarget;
+ Entity *target;
+ list<Entity*> N;
+
int health;
int reach;
int maxHealth;
@@ -36,13 +40,14 @@ class Creature: public Entity
int bite;
int amountAte;
int amountToGrow;
+ int pregnancyTime;
+ int expectedPregnancyTime;
bool hungry;
- bool gender;
+ bool pregnancyReady;
bool able;
-
- list<Entity*> N;
- Entity *target;
+ bool hasTarget;
+ bool wander;
};
#endif
diff --git a/inc/entity.hpp b/inc/entity.hpp
index 6587f11..a7b7f58 100644
--- a/inc/entity.hpp
+++ b/inc/entity.hpp
@@ -12,10 +12,14 @@ class Entity
SDL_Rect getRect(){return rect;};
virtual void eat(int bite){};
- virtual int getAmount(void){};
+ virtual void impregnate(void){};
+ virtual bool getGender(void){};
+ virtual int getAmount(void){};
protected:
int type;
+ int gender;
+ bool pregnate;
SDL_Rect rect;
SDL_Renderer* renderer;
};
diff --git a/inc/functions.hpp b/inc/functions.hpp
new file mode 100644
index 0000000..2ddcda9
--- /dev/null
+++ b/inc/functions.hpp
@@ -0,0 +1,12 @@
+#ifndef functions_h
+#define functions_h
+
+static double Distance(SDL_Rect A, SDL_Rect B){
+ return sqrt( pow(A.x-B.x,2) + pow(A.y-B.y,2));
+}
+
+static int map(int x, int inMin, int inMax, int outMin, int outMax){
+ return (x-inMin) * (outMax - outMin) / (inMax - inMin) + outMin;
+}
+
+#endif
diff --git a/inc/list.hpp b/inc/list.hpp
index 64ca522..cc78031 100644
--- a/inc/list.hpp
+++ b/inc/list.hpp
@@ -4,6 +4,7 @@
#include <SDL2/SDL.h>
#include <list>
+#include "functions.hpp"
#include "creature.hpp"
#include "resource.hpp"
#include "window.hpp"
@@ -16,7 +17,6 @@ class List
void Behavior();
void Place();
void Remove();
- double Distance(SDL_Rect A, SDL_Rect B){return sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2));};
list<Entity*> getNear(Creature C);
private:
diff --git a/inc/resource.hpp b/inc/resource.hpp
index 5c740fa..cb5946c 100644
--- a/inc/resource.hpp
+++ b/inc/resource.hpp
@@ -2,16 +2,15 @@
#define resource_h
#include "entity.hpp"
+#include "functions.hpp"
class Resource: public Entity
{
public:
Resource(Window m, SDL_Rect Rect);
- void eat(int bite);
-
int getAmount(){return amount;};
void grow();
- int map(int x, int inMin, int inMax, int outMin, int outMax);
+ void eat(int bite);
private:
int amount;
diff --git a/inc/timer.hpp b/inc/timer.hpp
index c8f43ff..d4e46e8 100644
--- a/inc/timer.hpp
+++ b/inc/timer.hpp
@@ -11,7 +11,7 @@ class Timer
void Stop();
void Pause();
void unPause();
- int getTicks();
+ int getTicks();
bool isStarted(){return started;};
bool isPaused(){return paused;};