summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@apollo>2017-01-10 09:49:32 -0600
committertom <tom@apollo>2017-01-10 09:49:32 -0600
commitf6f6d81c5634f659693914b7b74efcdd39ba5d4f (patch)
tree5b51e9b82ae36c648e212cc9c95fb8233dc181c1
parent20717aeb1b12a7179e7b29c3c8880f18b360a1c8 (diff)
-Replaced images with colored rectangles
-Removed various functions and variables pertaining to such images -Started migrating all uses of Location to SDL_Rect (I would preferably completly remove Location.hpp) -Scaled down resolution to 1080x640 (I would like to make these global constants)
-rw-r--r--Makefile2
-rwxr-xr-xexecbin0 -> 362688 bytes
-rw-r--r--img/Cbasic.pngbin3167 -> 0 bytes
-rw-r--r--img/Cdead.pngbin2806 -> 0 bytes
-rw-r--r--img/Rbasic.pngbin1185 -> 0 bytes
-rw-r--r--inc/creature.hpp6
-rw-r--r--inc/entity.hpp18
-rw-r--r--inc/resource.hpp4
-rw-r--r--src/creature.cpp23
-rw-r--r--src/entity.cpp31
-rw-r--r--src/list.cpp7
-rw-r--r--src/resource.cpp32
-rw-r--r--src/window.cpp2
13 files changed, 73 insertions, 52 deletions
diff --git a/Makefile b/Makefile
index 4fc413f..f05677a 100644
--- a/Makefile
+++ b/Makefile
@@ -8,4 +8,4 @@ COMPILER_FLAGS = -w -I$(DEPS)
LINKER_FLAGS = -g -lm -lSDL2 -lSDL2_image -std=c++11
all : $(OBJS)
- $(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o natures
+ $(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o exec
diff --git a/exec b/exec
new file mode 100755
index 0000000..b21bd27
--- /dev/null
+++ b/exec
Binary files differ
diff --git a/img/Cbasic.png b/img/Cbasic.png
deleted file mode 100644
index 01ba395..0000000
--- a/img/Cbasic.png
+++ /dev/null
Binary files differ
diff --git a/img/Cdead.png b/img/Cdead.png
deleted file mode 100644
index 226c75b..0000000
--- a/img/Cdead.png
+++ /dev/null
Binary files differ
diff --git a/img/Rbasic.png b/img/Rbasic.png
deleted file mode 100644
index a625a84..0000000
--- a/img/Rbasic.png
+++ /dev/null
Binary files differ
diff --git a/inc/creature.hpp b/inc/creature.hpp
index 636d960..bc23652 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -8,14 +8,14 @@
class Creature: public Entity
{
public:
- Creature(Window m, std::string s);
+ Creature(Window m, int size);
void Behavior();
void Action();
void Priority();
void setTarget();
void Move(Location l);
+
void giveN(list<Entity*> n){N = n;};
-
Location getLocation(){return L;};
double Distance(Location A, Location B){return sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2));};
int getHealth(){return health;};
@@ -31,7 +31,7 @@ class Creature: public Entity
bool hungry;
int speed = 1;
bool able;
- int bestSense = 100;
+ int bestSense = 100;
list<Entity*> N;
Entity *target;
diff --git a/inc/entity.hpp b/inc/entity.hpp
index 540e7b9..62c14d4 100644
--- a/inc/entity.hpp
+++ b/inc/entity.hpp
@@ -7,19 +7,21 @@
class Entity
{
public:
+ void Init(Window m);
+ void Init(Window m, Location z);
void Place();
- SDL_Texture* loadTexture(std::string path, Window main);
- Location getLocation(){return L;};
+
int getType(){return type;};
- virtual void eat(void) {};
- virtual int getAmount(void) {};
+ Location getLocation(){return L;};
+ SDL_Rect getRect(){return rect;};
+
+ virtual void eat(void){};
+ virtual int getAmount(void){};
protected:
- Location L;
- int height, width; //Dimensions of image on window
- int degrees = 0;
int type = 0;
- SDL_Texture* texture;
+ SDL_Rect rect;
+ Location L;
SDL_Renderer* renderer;
};
diff --git a/inc/resource.hpp b/inc/resource.hpp
index 968c208..5f70585 100644
--- a/inc/resource.hpp
+++ b/inc/resource.hpp
@@ -7,8 +7,8 @@
class Resource: public Entity
{
public:
- Resource(Window m, std::string s);
- Resource(Window m, std::string s, Location z);
+ Resource(Window m, int size);
+ Resource(Window m, int size, Location z);
void eat();
Location getLocation(){return L;};
diff --git a/src/creature.cpp b/src/creature.cpp
index ead0b2d..7e9011a 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -1,16 +1,18 @@
#include "creature.hpp"
-Creature::Creature(Window m, std::string s)
+Creature::Creature(Window m, int size)
{
- texture = loadTexture(s, m);
- renderer = m.getRenderer();
- health = 500;
- maxHealth = 1000;
-
- L.y=rand()%800;
- L.x=rand()%1200;
+ Init(m);
type = 1;
+
+ rect.h = rect.w = size;
+
+ L.x = rect.x;
+ L.y = rect.y;
+ health = 500;
+ maxHealth = 1000;
+
hungry = false;
hasTarget = false;
wander = false;
@@ -42,6 +44,9 @@ void Creature::Priority()
void Creature::setTarget()
{
+ if(hasTarget)
+ return;
+
for(list <Entity*>::iterator it = N.begin(); it!=N.end(); it++){
if((*it)->getType() == 2 && hungry){
if(!hasTarget){
@@ -117,4 +122,6 @@ void Creature::Move(Location l)
L.y-=speed;
}
}
+ rect.x = L.x;
+ rect.y = L.y;
}
diff --git a/src/entity.cpp b/src/entity.cpp
index 4f60851..be3e792 100644
--- a/src/entity.cpp
+++ b/src/entity.cpp
@@ -1,18 +1,27 @@
#include "entity.hpp"
-void Entity::Place()
+void Entity::Init(Window m)
+{
+ renderer = m.getRenderer();
+ rect.y = rand()%640;
+ rect.x = rand()%1080;
+}
+
+void Entity::Init(Window m, Location z)
{
- SDL_Rect rect = {L.x, L.y, width/8, height/8};
- SDL_RenderCopyEx(renderer,texture,NULL,&rect,degrees,NULL,SDL_FLIP_NONE);
+ renderer = m.getRenderer();
+ rect.y = z.y;
+ rect.x = z.x;
}
-SDL_Texture* Entity::loadTexture(string path, Window main)
+void Entity::Place()
{
- SDL_Surface* surface = IMG_Load(path.c_str());
- SDL_SetColorKey(surface, SDL_TRUE, SDL_MapRGB(surface->format, 255, 255, 255));
- height = surface->h;
- width = surface->w;
- SDL_Texture* texture = SDL_CreateTextureFromSurface(main.getRenderer(),surface);
- SDL_FreeSurface(surface);
- return texture;
+ if(type == 1)
+ SDL_SetRenderDrawColor(renderer,255,0,255,255);
+ else
+ SDL_SetRenderDrawColor(renderer,0,255,0,255);
+
+ SDL_RenderDrawRect(renderer, &rect);
+
+ SDL_SetRenderDrawColor(renderer,0,0,0,255);
}
diff --git a/src/list.cpp b/src/list.cpp
index e08531b..2fca4f4 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -5,12 +5,12 @@ List::List(Window m)
int i;
for(i=0;i<10;i++){
- Creature X(m,"img/Cbasic.png");
+ Creature X(m,10);
C.push_back(X);
}
for(i=0;i<100;i++){
- Resource Y(m,"img/Rbasic.png");
+ Resource Y(m,5);
R.push_back(Y);
}
@@ -41,7 +41,8 @@ void List::Behavior()
if(it->getHealth()<=0){
Location z = it->getLocation();
- Resource r = Resource(main,"img/Cdead.png",z);
+ SDL_Rect rect = it->getRect();
+ Resource r = Resource(main,rect.w,z);
R.push_back(r);
C.erase(it--);
}
diff --git a/src/resource.cpp b/src/resource.cpp
index 08929bc..0c07be3 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -1,27 +1,29 @@
#include "resource.hpp"
-Resource::Resource(Window m, std::string s)
-{
- texture = loadTexture(s, m);
- renderer = m.getRenderer();
-
- L.y = rand()%800;
- L.x = rand()%1200;
+Resource::Resource(Window m, int size)
+{
+ Init(m);
type = 2;
+ rect.h = rect.w = size;
+
+ L.x = rect.x;
+ L.y = rect.y;
+
amount = 100;
}
-Resource::Resource(Window m, std::string s, Location z)
+Resource::Resource(Window m, int size, Location z)
{
- texture = loadTexture(s, m);
- renderer = m.getRenderer();
-
- L.y = z.y;
- L.x = z.x;
+ Init(m,z);
type = 2;
-
- amount = 100;
+
+ rect.h = rect.w = size;
+
+ L.x = rect.x;
+ L.y = rect.y;
+
+ amount = 200;
}
void Resource::eat()
diff --git a/src/window.cpp b/src/window.cpp
index 5df97cf..fccdef0 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,1280,800,SDL_WINDOW_SHOWN);
+ main = SDL_CreateWindow("main",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,1080,640,SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(main,-1,SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
}