summaryrefslogtreecommitdiff
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
parent22cd24a1fe33b6bc9f52a600feb5cdb8d868d50f (diff)
fleshed out list, locations of all creatures and resources are now within
-rw-r--r--inc/creature.hpp9
-rw-r--r--inc/list.hpp3
-rw-r--r--inc/location.hpp17
-rw-r--r--inc/main.hpp1
-rw-r--r--inc/resource.hpp5
-rw-r--r--inc/window.hpp1
-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
12 files changed, 96 insertions, 33 deletions
diff --git a/inc/creature.hpp b/inc/creature.hpp
index ab4b328..f72dfbc 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -2,17 +2,22 @@
#define creature_h
#include "entity.hpp"
+#include "location.hpp"
class Creature: public Entity
{
public:
Creature(Window m, std::string s);
void Behavior();
- void Action();
-
+ void Action();
+ Location getLocation();
+
private:
int xT;
int yT;
+ int hp;
+ int hu;
+ Location K[3];
};
#endif
diff --git a/inc/list.hpp b/inc/list.hpp
index 240fa95..203ad7f 100644
--- a/inc/list.hpp
+++ b/inc/list.hpp
@@ -4,6 +4,7 @@
#include "creature.hpp"
#include "resource.hpp"
#include "window.hpp"
+#include "location.hpp"
class List
{
@@ -16,7 +17,7 @@ class List
//Window main;
std::vector<Resource> R;
std::vector<Creature> C;
- int ** L;
+ std::vector<Location> L;
};
#endif
diff --git a/inc/location.hpp b/inc/location.hpp
new file mode 100644
index 0000000..c4428f5
--- /dev/null
+++ b/inc/location.hpp
@@ -0,0 +1,17 @@
+#ifndef location_h
+#define location_h
+
+class Location
+{
+ public:
+ Location(){x=y=t=0;};
+ Location(int x, int y, int z){};
+ int getType(){return t;};
+
+ private:
+ int x;
+ int y;
+ int t;
+};
+
+#endif
diff --git a/inc/main.hpp b/inc/main.hpp
index 4360cf9..c6f51e3 100644
--- a/inc/main.hpp
+++ b/inc/main.hpp
@@ -7,5 +7,6 @@
#include "creature.hpp"
#include "resource.hpp"
#include "list.hpp"
+#include "location.hpp"
#endif
diff --git a/inc/resource.hpp b/inc/resource.hpp
index 986a03d..2738f44 100644
--- a/inc/resource.hpp
+++ b/inc/resource.hpp
@@ -2,11 +2,16 @@
#define resource_h
#include "entity.hpp"
+#include "location.hpp"
class Resource: public Entity
{
public:
Resource(Window m, std::string s);
+ Location getLocation();
+
+ private:
+ int amount;
};
#endif
diff --git a/inc/window.hpp b/inc/window.hpp
index 2f65b04..d3436d8 100644
--- a/inc/window.hpp
+++ b/inc/window.hpp
@@ -1,6 +1,7 @@
#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>
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;
-};
+}