diff options
-rw-r--r-- | inc/constants.hpp | 3 | ||||
-rw-r--r-- | inc/creature.hpp | 2 | ||||
-rw-r--r-- | src/creature.cpp | 5 | ||||
-rw-r--r-- | src/main.cpp | 12 |
4 files changed, 17 insertions, 5 deletions
diff --git a/inc/constants.hpp b/inc/constants.hpp index fd00fb1..5ec55b2 100644 --- a/inc/constants.hpp +++ b/inc/constants.hpp @@ -3,7 +3,7 @@ const int CREATURES = 10; const int RESOURCES = 100; -const int MINIMUM_RESOURCES = 70; +const int MINIMUM_RESOURCES = 80; const int WINDOW_X = 500; const int WINDOW_Y = 500; @@ -20,6 +20,7 @@ const int CREATURE_SIZE_START = 5; const int CREATURE_BITE = 10; const int CREATURE_AMOUNT_TO_GROW = 50; const int CREATURE_EXPECTED_PREGNANCY_TIME = 100; +const int CREATURE_EXPECTED_AGE = 100000; const int RESOURCE_SIZE_START = 1; const int RESOURCE_SIZE_MAX = 4; diff --git a/inc/creature.hpp b/inc/creature.hpp index 79ec4c3..1676be0 100644 --- a/inc/creature.hpp +++ b/inc/creature.hpp @@ -42,6 +42,8 @@ class Creature: public Entity int amountToGrow; int pregnancyTime; int expectedPregnancyTime; + int age; + int expectedAge; bool hungry; bool pregnancyReady; diff --git a/src/creature.cpp b/src/creature.cpp index ff6290d..9e51b04 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -19,8 +19,10 @@ Creature::Creature(Window m, SDL_Rect R) bite = CREATURE_BITE; amountToGrow = CREATURE_AMOUNT_TO_GROW; expectedPregnancyTime = CREATURE_EXPECTED_PREGNANCY_TIME; + expectedAge = CREATURE_EXPECTED_AGE; gender = rand() % 2; + age = 0; hungry = false; hasTarget = false; wander = false; @@ -48,6 +50,9 @@ void Creature::Behavior() pregnancyReady = true; } + age++; + if(age > expectedAge) + health = 0; } void Creature::Priority() diff --git a/src/main.cpp b/src/main.cpp index 460582a..127c306 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,6 +8,7 @@ int main() Event e;
Timer fps;
+ int speed = 60;
while(e.gRun())
{
@@ -17,8 +18,11 @@ int main() {
if(e.gEventType() == SDL_QUIT)
e.off();
- //else if(e.gEventType() == SDL_KEYDOWN)
- // eventHandle(e.gEvent());
+ else if(e.gEventType() == SDL_KEYDOWN)
+ switch(e.gEvent().key.keysym.sym){
+ case SDLK_RIGHT: speed+=30; break;
+ case SDLK_LEFT : if(speed >30) speed-=30; break;
+ }
}
main.Clear();
@@ -29,8 +33,8 @@ int main() main.Render();
- if(fps.getTicks() < (1000 / 60))
- SDL_Delay((1000 / 60) - fps.getTicks());
+ if(fps.getTicks() < (1000 / speed))
+ SDL_Delay((1000 / speed) - fps.getTicks());
}
main.Destroy();
|