From 22cd24a1fe33b6bc9f52a600feb5cdb8d868d50f Mon Sep 17 00:00:00 2001 From: tom Date: Tue, 5 May 2015 15:25:32 -0500 Subject: 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 --- Makefile | 2 +- inc/list.hpp | 5 +++-- inc/window.hpp | 2 ++ src/creature.cpp | 9 ++++++++- src/list.cpp | 28 +++++++++++++++++++++++++--- src/main.cpp | 16 +++++++--------- src/resource.cpp | 1 + 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 R; std::vector 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 #include #include +#include +#include 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; } -- cgit v1.2.3