From ffcee12acf3fe3f972f322c18b3203212682205d Mon Sep 17 00:00:00 2001 From: tom Date: Thu, 7 May 2015 12:35:15 -0500 Subject: woo! detection is implemented albeit shitty --- src/list.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/list.cpp') diff --git a/src/list.cpp b/src/list.cpp index c3246c9..2612d3e 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -19,10 +19,20 @@ List::List(Window m) void List::Behavior() { - int i; + int i, j; + std::vector Z; + for(i = 0; i < C.size(); i++) { C[i].Behavior(); + for(j = 0; j < L.size(); j++) + if(200>(Distance(C[i].getLocation(),L[j]))) + { + Z.push_back(L[j]); + } + + C[i].giveKnown(Z); + Z.clear(); } } @@ -31,7 +41,7 @@ void List::Place() int i; for(i = 0;i < L.size(); i++) - if(L.getType()==1) + if(L[i].t==1) L.erase(L.begin()+i); for(i = 0; i < C.size(); i++) @@ -45,3 +55,10 @@ void List::Place() R[i].Place(); } } + +double List::Distance(Location A, Location B) +{ + double z = sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2)); + //std::cout << z << "\n"; + return z; +} -- cgit v1.2.3 From c63d77ddddb69ef0f641d90a8c3922fdc356224c Mon Sep 17 00:00:00 2001 From: dakjos Date: Thu, 7 May 2015 19:53:39 -0500 Subject: Some variable names changed and many comments made so I understand what the fuck is going on --- src/list.cpp | 54 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 24 deletions(-) (limited to 'src/list.cpp') diff --git a/src/list.cpp b/src/list.cpp index 2612d3e..0101d8c 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -1,14 +1,16 @@ #include "list.hpp" -List::List(Window m) +List::List(Window m) //Constructor { int i; + //Creates 5 creatures, inserts them into vector C for(i=0;i<5;i++) { - Creature X = Creature(m,"img/Cbasic.png"); + Creature X(m,"img/Cbasic.png"); C.push_back(X); } + //Creates 5 resources, inserts them into vector R; inserts locations of resources into vector L for(i=0;i<5;i++) { Resource Y(m,"img/Rbasic.png"); @@ -17,48 +19,52 @@ List::List(Window m) } } -void List::Behavior() -{ - int i, j; - std::vector Z; - - for(i = 0; i < C.size(); i++) - { - C[i].Behavior(); - for(j = 0; j < L.size(); j++) - if(200>(Distance(C[i].getLocation(),L[j]))) - { - Z.push_back(L[j]); - } - - C[i].giveKnown(Z); - Z.clear(); - } -} - void List::Place() { int i; + //if any locations are creatures, erases them from vector L for(i = 0;i < L.size(); i++) - if(L[i].t==1) + if(L[i].type==1) L.erase(L.begin()+i); + //places each creature on window, inserts their locations into vector L for(i = 0; i < C.size(); i++) { C[i].Place(); L.push_back(C[i].getLocation()); } + //places all resources for(i = 0; i < R.size(); i++) { R[i].Place(); } } +void List::Behavior() +{ + int i, j; + std::vector Z; + + // + for(i = 0; i < C.size(); i++) + { + C[i].Behavior(); //executes the behavior of the creature at i + for(j = 0; j < L.size(); j++) + if(200>(Distance(C[i].getLocation(),L[j]))) //if the distance between the creature and L[j] is less than 200, insert L[j] into vector Z. + { + Z.push_back(L[j]); + } + + C[i].giveKnown(Z); //sets creature's target location? + Z.clear(); //clear vector Z for next creature + } +} + double List::Distance(Location A, Location B) { - double z = sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2)); - //std::cout << z << "\n"; + //computes distance between two points + double z = sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2)); return z; } -- cgit v1.2.3 From 84f94931fa790572b3ce57d72e290f0bd860c661 Mon Sep 17 00:00:00 2001 From: tom Date: Fri, 8 May 2015 08:05:57 -0500 Subject: merging --- src/list.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/list.cpp') diff --git a/src/list.cpp b/src/list.cpp index 2612d3e..ee0d14d 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -3,7 +3,7 @@ List::List(Window m) { int i; - for(i=0;i<5;i++) + for(i=0;i<10;i++) { Creature X = Creature(m,"img/Cbasic.png"); C.push_back(X); -- cgit v1.2.3 From 04069434be15c06666a7493b1b6329a78c00d1d1 Mon Sep 17 00:00:00 2001 From: tom Date: Fri, 8 May 2015 08:09:32 -0500 Subject: merging --- src/list.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'src/list.cpp') diff --git a/src/list.cpp b/src/list.cpp index c21dd52..b86f077 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -3,12 +3,8 @@ List::List(Window m) //Constructor { int i; -<<<<<<< HEAD + for(i=0;i<10;i++) -======= - //Creates 5 creatures, inserts them into vector C - for(i=0;i<5;i++) ->>>>>>> c63d77ddddb69ef0f641d90a8c3922fdc356224c { Creature X(m,"img/Cbasic.png"); C.push_back(X); -- cgit v1.2.3 From 8c5121486a0e5d94ae5e5ee67370a31530cf8b6f Mon Sep 17 00:00:00 2001 From: tom Date: Fri, 8 May 2015 08:23:06 -0500 Subject: fixed some comments and cleaned around --- src/list.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/list.cpp') diff --git a/src/list.cpp b/src/list.cpp index b86f077..2140a75 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -65,6 +65,5 @@ void List::Behavior() double List::Distance(Location A, Location B) { //computes distance between two points - double z = sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2)); - return z; + return sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2)); } -- cgit v1.2.3