summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@apollo>2017-01-11 02:19:07 -0600
committertom <tom@apollo>2017-01-11 02:19:07 -0600
commitb97a54b8acd113e99871fdb0f683e27e0912bf42 (patch)
tree0c32320f225569da513a505d73dd72a506f08c95
parentf6f6d81c5634f659693914b7b74efcdd39ba5d4f (diff)
-removed all magic numbers and placed them in a constants header
-removed unused libraries and redid all header files
-rwxr-xr-xexecbin362688 -> 318784 bytes
-rw-r--r--inc/constants.hpp19
-rw-r--r--inc/creature.hpp12
-rw-r--r--inc/entity.hpp2
-rw-r--r--inc/event.hpp2
-rw-r--r--inc/list.hpp3
-rw-r--r--inc/timer.hpp2
-rw-r--r--inc/window.hpp12
-rw-r--r--src/creature.cpp8
-rw-r--r--src/entity.cpp8
-rw-r--r--src/list.cpp8
-rw-r--r--src/resource.cpp4
-rw-r--r--src/window.cpp2
13 files changed, 49 insertions, 33 deletions
diff --git a/exec b/exec
index b21bd27..9a0c8d7 100755
--- a/exec
+++ b/exec
Binary files differ
diff --git a/inc/constants.hpp b/inc/constants.hpp
new file mode 100644
index 0000000..2a5b8fb
--- /dev/null
+++ b/inc/constants.hpp
@@ -0,0 +1,19 @@
+#ifndef constants_h
+#define constants_h
+
+const int CREATURES = 10;
+const int RESOURCES = 100;
+const int WINDOW_X = 1080;
+const int WINDOW_Y = 640;
+
+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 = 10;
+
+const int RESOURCE_SIZE = 5;
+const int RESOURCE_AMOUNT = 100;
+
+#endif
diff --git a/inc/creature.hpp b/inc/creature.hpp
index bc23652..8515bc0 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -1,9 +1,12 @@
#ifndef creature_h
#define creature_h
-#include "entity.hpp"
-#include "resource.hpp"
+#include <SDL2/SDL.h>
+#include <list>
+
#include "location.hpp"
+#include "entity.hpp"
+#include "constants.hpp"
class Creature: public Entity
{
@@ -27,11 +30,12 @@ class Creature: public Entity
bool wander;
Location wTarget;
int health;
+ int reach = CREATURE_REACH;
int maxHealth;
bool hungry;
- int speed = 1;
+ int speed = CREATURE_SPEED;
bool able;
- int bestSense = 100;
+ int bestSense = CREATURE_BEST_SENSE;
list<Entity*> N;
Entity *target;
diff --git a/inc/entity.hpp b/inc/entity.hpp
index 62c14d4..d02f689 100644
--- a/inc/entity.hpp
+++ b/inc/entity.hpp
@@ -19,7 +19,7 @@ class Entity
virtual int getAmount(void){};
protected:
- int type = 0;
+ int type;
SDL_Rect rect;
Location L;
SDL_Renderer* renderer;
diff --git a/inc/event.hpp b/inc/event.hpp
index e9025f0..c1d528e 100644
--- a/inc/event.hpp
+++ b/inc/event.hpp
@@ -1,7 +1,7 @@
#ifndef event_h
#define event_h
-#include "window.hpp"
+#include <SDL2/SDL.h>
class Event
{
diff --git a/inc/list.hpp b/inc/list.hpp
index 3ad8477..8cf409b 100644
--- a/inc/list.hpp
+++ b/inc/list.hpp
@@ -1,10 +1,13 @@
#ifndef list_h
#define list_h
+#include <list>
+
#include "creature.hpp"
#include "resource.hpp"
#include "window.hpp"
#include "location.hpp"
+#include "constants.hpp"
class List
{
diff --git a/inc/timer.hpp b/inc/timer.hpp
index 1213311..c8f43ff 100644
--- a/inc/timer.hpp
+++ b/inc/timer.hpp
@@ -1,7 +1,7 @@
#ifndef timer_h
#define timer_h
-#include "window.hpp"
+#include <SDL2/SDL.h>
class Timer
{
diff --git a/inc/window.hpp b/inc/window.hpp
index 49bdb09..1a1a5a7 100644
--- a/inc/window.hpp
+++ b/inc/window.hpp
@@ -1,20 +1,10 @@
#ifndef window_h
#define window_h
-//Theres alot here that are probs not used, needs cleaning
#include <SDL2/SDL.h>
-#include <SDL2/SDL_image.h>
-#include <string>
-#include <cmath>
-#include <stdlib.h>
-#include <time.h>
-#include <iostream>
-#include <vector>
-#include <chrono>
-#include <random>
-#include <list>
#include <algorithm>
+#include "constants.hpp"
using namespace std;
diff --git a/src/creature.cpp b/src/creature.cpp
index 7e9011a..b81153e 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -10,8 +10,8 @@ Creature::Creature(Window m, int size)
L.x = rect.x;
L.y = rect.y;
- health = 500;
- maxHealth = 1000;
+ health = CREATURE_START_HEALTH;
+ maxHealth = CREATURE_MAX_HEALTH;
hungry = false;
hasTarget = false;
@@ -61,7 +61,7 @@ void Creature::setTarget()
if(!hasTarget&&!wander){
wander = true;
- wTarget = Location(rand()%1200,rand()%800);
+ wTarget = Location(rand()%WINDOW_X,rand()%WINDOW_Y);
}
}
@@ -69,7 +69,7 @@ void Creature::setTarget()
void Creature::Action()
{
if(hasTarget){
- if(Distance(L,target->getLocation())<5){
+ if(Distance(L,target->getLocation())<reach){
target->eat();
health+=10;
}
diff --git a/src/entity.cpp b/src/entity.cpp
index be3e792..ff6799e 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -3,8 +3,8 @@
void Entity::Init(Window m)
{
renderer = m.getRenderer();
- rect.y = rand()%640;
- rect.x = rand()%1080;
+ rect.y = rand()%WINDOW_Y;
+ rect.x = rand()%WINDOW_X;
}
void Entity::Init(Window m, Location z)
@@ -21,7 +21,7 @@ void Entity::Place()
else
SDL_SetRenderDrawColor(renderer,0,255,0,255);
- SDL_RenderDrawRect(renderer, &rect);
+ SDL_RenderFillRect(renderer, &rect);
- SDL_SetRenderDrawColor(renderer,0,0,0,255);
+ SDL_SetRenderDrawColor(renderer,0,0,0,0);
}
diff --git a/src/list.cpp b/src/list.cpp
index 2fca4f4..b5e05da 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -4,13 +4,13 @@ List::List(Window m)
{
int i;
- for(i=0;i<10;i++){
- Creature X(m,10);
+ for(i=0;i<CREATURES;i++){
+ Creature X(m,CREATURE_SIZE);
C.push_back(X);
}
- for(i=0;i<100;i++){
- Resource Y(m,5);
+ for(i=0;i<RESOURCES;i++){
+ Resource Y(m,RESOURCE_SIZE);
R.push_back(Y);
}
diff --git a/src/resource.cpp b/src/resource.cpp
index 0c07be3..326c047 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -10,7 +10,7 @@ Resource::Resource(Window m, int size)
L.x = rect.x;
L.y = rect.y;
- amount = 100;
+ amount = RESOURCE_AMOUNT;
}
Resource::Resource(Window m, int size, Location z)
@@ -23,7 +23,7 @@ Resource::Resource(Window m, int size, Location z)
L.x = rect.x;
L.y = rect.y;
- amount = 200;
+ amount = RESOURCE_AMOUNT;
}
void Resource::eat()
diff --git a/src/window.cpp b/src/window.cpp
index fccdef0..f7868a4 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -3,7 +3,7 @@
Window::Window()
{
SDL_Init(SDL_INIT_VIDEO);
- main = SDL_CreateWindow("main",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,1080,640,SDL_WINDOW_SHOWN);
+ main = SDL_CreateWindow("main",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,WINDOW_X,WINDOW_Y,SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(main,-1,SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
}