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 --- src/creature.cpp | 9 ++++++++- src/list.cpp | 28 +++++++++++++++++++++++++--- src/main.cpp | 16 +++++++--------- src/resource.cpp | 1 + 4 files changed, 41 insertions(+), 13 deletions(-) (limited to 'src') 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