summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-05-05 15:25:32 -0500
committertom <tom@ground-control>2015-05-05 15:25:32 -0500
commit22cd24a1fe33b6bc9f52a600feb5cdb8d868d50f (patch)
treea2c854b5ed2b746017bd975a241f85b7080ffa4c
parentafcf5f509a318ee66a16690f204f03dee701722e (diff)
fixed list to make it easy to add more creatures/resources.
need to figure out how to generate more random numbers after - implement resource amount and ability to eat
-rw-r--r--Makefile2
-rw-r--r--inc/list.hpp5
-rw-r--r--inc/window.hpp2
-rw-r--r--src/creature.cpp9
-rw-r--r--src/list.cpp28
-rw-r--r--src/main.cpp16
-rw-r--r--src/resource.cpp1
7 files changed, 47 insertions, 16 deletions
diff --git a/Makefile b/Makefile
index 4dea6cc..ca9c1ee 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CC = g++
COMPILER_FLAGS = -w -I$(DEPS)
-LINKER_FLAGS = -lSDL2 -lSDL2_image
+LINKER_FLAGS = -lSDL2 -lSDL2_image -std=c++11
all : $(OBJS)
$(CC) $(OBJS) $(COMPILER_FLAGS) $(LINKER_FLAGS) -o nature
diff --git a/inc/list.hpp b/inc/list.hpp
index 6ae906d..240fa95 100644
--- a/inc/list.hpp
+++ b/inc/list.hpp
@@ -10,12 +10,13 @@ class List
public:
List(Window m);
void Behavior();
+ void Place();
private:
+ //Window main;
std::vector<Resource> R;
std::vector<Creature> C;
- Window main;
int ** L;
};
-#endif \ No newline at end of file
+#endif
diff --git a/inc/window.hpp b/inc/window.hpp
index b28da56..2f65b04 100644
--- a/inc/window.hpp
+++ b/inc/window.hpp
@@ -9,6 +9,8 @@
#include <time.h>
#include <iostream>
#include <vector>
+#include <chrono>
+#include <random>
class Window
{
diff --git a/src/creature.cpp b/src/creature.cpp
index c9f9fa0..8e86c0d 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -4,7 +4,14 @@ Creature::Creature(Window m, std::string s)
{
texture = loadTexture(s, m);
renderer = m.getRenderer();
- x=y=500;
+
+ srand(time(NULL));
+ int z = rand()%800;
+ y=z;
+
+ z = rand()%800;
+ x=z;
+ std::cout << x << ' ' << y << std::endl;
//For the test resource
xT=yT=300;
diff --git a/src/list.cpp b/src/list.cpp
index e1695d6..7d6f10e 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -2,6 +2,28 @@
List::List(Window m)
{
- C.insert(Creature(m,"img/Cbasic.png"));
- R.insert(Resource(m,"img/Rbasic.png"));
-} \ No newline at end of file
+ Creature X0(m,"img/Cbasic.png");
+ C.push_back(X0);
+ Creature X1(m,"img/Cbasic.png");
+ C.push_back(X1);
+
+ Resource Y(m,"img/Rbasic.png");
+ R.push_back(Y);
+};
+
+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();
+
+ for(i = 0; i < R.size(); i++)
+ R[i].Place();
+}
diff --git a/src/main.cpp b/src/main.cpp
index 4435ad9..0e26dc5 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -3,9 +3,7 @@
int main()
{
Window main;
- //Creature testcreature(main, "img/Cbasic.png");
- //Resource testresource(main, "img/Rbasic.png");
- List(main);
+ List L(main);
Event e;
while(e.gRun())
@@ -17,14 +15,14 @@ int main()
//else if(e.gEventType() == SDL_KEYDOWN)
// eventHandle(e.gEvent());
}
- main.Clear();
-
- //testcreature.Behavior();
- //testcreature.Place();
- //testresource.Place();
+ main.Clear();
+
+ L.Behavior();
+ L.Place();
+
main.Render();
- SDL_Delay(10);
+ SDL_Delay(5);
}
main.Destroy();
diff --git a/src/resource.cpp b/src/resource.cpp
index 7f39493..ac89e4b 100644
--- a/src/resource.cpp
+++ b/src/resource.cpp
@@ -4,5 +4,6 @@ Resource::Resource(Window m, std::string s)
{
texture = loadTexture(s, m);
renderer = m.getRenderer();
+ //int z = %
x=y=300;
}