Delayed root hatching
authorChristoph Sommer <mail@christoph-sommer.de>
Sat, 26 May 2007 17:42:23 +0000 (17:42 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sat, 26 May 2007 17:42:23 +0000 (17:42 +0000)
SVN-Revision: 5034

src/badguy/root.cpp
src/badguy/root.hpp

index 6fa949e..cad33cb 100644 (file)
 
 #include "root.hpp"
 #include "sprite/sprite_manager.hpp"
+#include "timer.hpp"
 
 static const float SPEED_GROW = 256;
 static const float SPEED_SHRINK = 128;
+static const float HATCH_TIME = 0.75;
 
 Root::Root(const Vector& pos)
   : BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_TILES-1),
@@ -55,7 +57,13 @@ void
 Root::active_update(float elapsed_time)
 {
   if (mystate == STATE_APPEARING) {  
-    if (base_sprite->animation_done()) mystate = STATE_GROWING;
+    if (base_sprite->animation_done()) {
+      hatch_timer.start(HATCH_TIME);
+      mystate = STATE_HATCHING;
+    }
+  }
+  if (mystate == STATE_HATCHING) {
+    if (!hatch_timer.started()) mystate = STATE_GROWING;
   }
   else if (mystate == STATE_GROWING) {
     offset_y -= elapsed_time * SPEED_GROW;
index 32ec2fa..d693f23 100644 (file)
@@ -22,6 +22,8 @@
 #include <memory>
 #include "badguy.hpp"
 
+class Timer;
+
 class Root : public BadGuy
 {
 public:
@@ -38,11 +40,12 @@ public:
 
 protected:
   enum MyState {
-    STATE_APPEARING, STATE_GROWING, STATE_SHRINKING, STATE_VANISHING
+    STATE_APPEARING, STATE_HATCHING, STATE_GROWING, STATE_SHRINKING, STATE_VANISHING
   };
   MyState mystate;
   std::auto_ptr<Sprite> base_sprite;
   float offset_y;
+  Timer hatch_timer;
 };
 
 #endif