diff options
| author | tom <tombarrett@siu.edu> | 2017-02-07 13:18:44 -0600 | 
|---|---|---|
| committer | tom <tombarrett@siu.edu> | 2017-02-07 13:18:44 -0600 | 
| commit | ba6b1fa8fdc3a0856a720695dd40efadc6e5889c (patch) | |
| tree | df79363310177145c4e940b144e0fe204d5a0ddf /src | |
| parent | 3e0bec85d3428d683fea5d0f08c8e287989ba372 (diff) | |
-added aging
-added speed increasing, but right now it is on arrow keys due to sdl errors with + and -, eventually the arrow keys will be used to pan the camera, and speed will be done with a graphic and the + and - keys
Diffstat (limited to 'src')
| -rw-r--r-- | src/creature.cpp | 5 | ||||
| -rw-r--r-- | src/main.cpp | 12 | 
2 files changed, 13 insertions, 4 deletions
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();
  | 
