summaryrefslogtreecommitdiff
path: root/src
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 /src
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)
Diffstat (limited to 'src')
-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
5 files changed, 57 insertions, 38 deletions
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);
}