summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-05-05 21:01:52 -0500
committertom <tom@ground-control>2015-05-05 21:01:52 -0500
commitaaf0a73578ecbb8212e0d224d6fff68a229b1f48 (patch)
tree46f6d91c1bc02e434812af59477e11fb5e521713 /src
parent22cd24a1fe33b6bc9f52a600feb5cdb8d868d50f (diff)
fleshed out list, locations of all creatures and resources are now within
Diffstat (limited to 'src')
-rw-r--r--src/creature.cpp30
-rw-r--r--src/event.cpp10
-rw-r--r--src/list.cpp27
-rw-r--r--src/main.cpp4
-rw-r--r--src/resource.cpp12
-rw-r--r--src/window.cpp10
6 files changed, 63 insertions, 30 deletions
diff --git a/src/creature.cpp b/src/creature.cpp
index 8e86c0d..cc3fa08 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -4,23 +4,25 @@ Creature::Creature(Window m, std::string s)
{
texture = loadTexture(s, m);
renderer = m.getRenderer();
+ hp = 100;
+ hu = 0;
- srand(time(NULL));
- int z = rand()%800;
- y=z;
-
- z = rand()%800;
- x=z;
- std::cout << x << ' ' << y << std::endl;
-
+ int zy = rand()%800;
+ int zx = rand()%1200;
+ y=zy;
+ x=zx;
+ //std::cout << x << ' ' << y << std::endl;
+
//For the test resource
xT=yT=300;
}
void Creature::Behavior()
{
+ hp--;
//Detection
+
//Priorities
//Action
@@ -34,15 +36,19 @@ void Creature::Action()
return; //eat//reproduce//etc;
if(x==xT)
+ {
if(y<yT)
y++;
else
y--;
+ }
else if(y==yT)
+ {
if(x<xT)
x++;
else
x--;
+ }
else
{
int z = rand()%2;
@@ -55,10 +61,16 @@ void Creature::Action()
}
else
{
- if(y<xT)
+ if(y<yT)
y++;
else
y--;
}
}
}
+
+Location Creature::getLocation()
+{
+ Location L(x,y,1);
+ return L;
+}
diff --git a/src/event.cpp b/src/event.cpp
index ba7fda8..56c4951 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -3,12 +3,12 @@
Event::Event()
{
run = true;
-};
+}
int Event::Poll()
{
SDL_PollEvent(&v);
-};
+}
void Event::off()
{
@@ -18,15 +18,15 @@ void Event::off()
bool Event::gRun()
{
return run;
-};
+}
SDL_Event& Event::gEvent()
{
SDL_Event* x = &v;
return *x;
-};
+}
int Event::gEventType()
{
return v.type;
-};
+}
diff --git a/src/list.cpp b/src/list.cpp
index 7d6f10e..b8a809c 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -2,28 +2,41 @@
List::List(Window m)
{
- Creature X0(m,"img/Cbasic.png");
- C.push_back(X0);
- Creature X1(m,"img/Cbasic.png");
- C.push_back(X1);
+ int i;
+ for(i=0;i<5;i++)
+ {
+ Creature X = Creature(m,"img/Cbasic.png");
+ C.push_back(X);
+ }
- Resource Y(m,"img/Rbasic.png");
- R.push_back(Y);
-};
+ for(i=0;i<5;i++)
+ {
+ Resource Y(m,"img/Rbasic.png");
+ R.push_back(Y);
+ L.push_back(Y.getLocation());
+ }
+}
void List::Behavior()
{
int i;
for(i = 0; i < C.size(); i++)
+ {
C[i].Behavior();
+ }
}
void List::Place()
{
int i;
for(i = 0; i < C.size(); i++)
+ {
C[i].Place();
+ L.push_back(C[i].getLocation());
+ }
for(i = 0; i < R.size(); i++)
+ {
R[i].Place();
+ }
}
diff --git a/src/main.cpp b/src/main.cpp
index 0e26dc5..1dec02c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -15,11 +15,11 @@ int main()
//else if(e.gEventType() == SDL_KEYDOWN)
// eventHandle(e.gEvent());
}
-
+
main.Clear();
- L.Behavior();
L.Place();
+ L.Behavior();
main.Render();
SDL_Delay(5);
diff --git a/src/resource.cpp b/src/resource.cpp
index ac89e4b..a087aca 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -4,6 +4,14 @@ Resource::Resource(Window m, std::string s)
{
texture = loadTexture(s, m);
renderer = m.getRenderer();
- //int z = %
- x=y=300;
+ int zy = rand()%800;
+ int zx = rand()%1200;
+ y=zy;
+ x=zx;
+}
+
+Location Resource::getLocation()
+{
+ Location L(x,y,2);
+ return L;
}
diff --git a/src/window.cpp b/src/window.cpp
index 8d6a566..b25f11e 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -6,26 +6,26 @@ Window::Window()
main = SDL_CreateWindow("main",SDL_WINDOWPOS_UNDEFINED,SDL_WINDOWPOS_UNDEFINED,1280,800,SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(main,-1,SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 0);
-};
+}
void Window::Destroy()
{
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(main);
SDL_Quit();
-};
+}
void Window::Clear()
{
SDL_RenderClear(renderer);
-};
+}
void Window::Render()
{
SDL_RenderPresent(renderer);
-};
+}
SDL_Renderer* Window::getRenderer()
{
return renderer;
-};
+}