diff options
author | tom <tom@ground-control> | 2015-05-02 17:31:50 -0500 |
---|---|---|
committer | tom <tom@ground-control> | 2015-05-02 17:31:50 -0500 |
commit | 5d97a0154ed1c5584c50884e086dcaa3536e5672 (patch) | |
tree | b3c96e7a30ada7995a02c3538d9f3ef9eb0bcd1c | |
parent | 467a25d8db798e8b590773bb0b89eac36537b87a (diff) |
added basic movement
-rw-r--r-- | inc/window.h | 1 | ||||
-rw-r--r-- | src/creature.cpp | 26 | ||||
-rw-r--r-- | src/main.cpp | 1 |
3 files changed, 20 insertions, 8 deletions
diff --git a/inc/window.h b/inc/window.h index 17ba597..d2dd801 100644 --- a/inc/window.h +++ b/inc/window.h @@ -7,6 +7,7 @@ #include <cmath> #include <stdlib.h> #include <time.h> +#include <iostream> class Window { diff --git a/src/creature.cpp b/src/creature.cpp index 207d3bd..d958d09 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -22,26 +22,36 @@ void Creature::Behavior() void Creature::Action() { - //if(isclose) - // eat//reproduce//etc; + //std::cout << (sqrt(((x-xT)^2)+((y-yT)^2)); + if((sqrt(((x-xT)^2)+((y-yT)^2)))<2) + return; //eat//reproduce//etc; if(x==xT) - { if(y<yT) y++; else y--; - } else if(y==yT) - { if(x<xT) x++; else x--; - } else { - srand(time(NULL)); - int z = rand()%1; + int z = rand()%2; + if(z) + { + if(x<xT) + x++; + else + x--; + } + else + { + if(y<xT) + y++; + else + y--; + } } } diff --git a/src/main.cpp b/src/main.cpp index 087ec78..1f78c65 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ int main() testcreature.Place();
testresource.Place();
main.Render();
+ SDL_Delay(10);
}
main.Destroy();
|