Added to ghosttree: roots growing from below
authorChristoph Sommer <mail@christoph-sommer.de>
Sat, 26 May 2007 17:32:29 +0000 (17:32 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sat, 26 May 2007 17:32:29 +0000 (17:32 +0000)
SVN-Revision: 5033

data/images/creatures/ghosttree/root-base-0.png [new file with mode: 0644]
data/images/creatures/ghosttree/root-base-1.png [new file with mode: 0644]
data/images/creatures/ghosttree/root-base-2.png [new file with mode: 0644]
data/images/creatures/ghosttree/root-base-3.png [new file with mode: 0644]
data/images/creatures/ghosttree/root-base.sprite [new file with mode: 0644]
src/badguy/ghosttree.cpp
src/badguy/root.cpp
src/badguy/root.hpp

diff --git a/data/images/creatures/ghosttree/root-base-0.png b/data/images/creatures/ghosttree/root-base-0.png
new file mode 100644 (file)
index 0000000..0d11710
Binary files /dev/null and b/data/images/creatures/ghosttree/root-base-0.png differ
diff --git a/data/images/creatures/ghosttree/root-base-1.png b/data/images/creatures/ghosttree/root-base-1.png
new file mode 100644 (file)
index 0000000..1397890
Binary files /dev/null and b/data/images/creatures/ghosttree/root-base-1.png differ
diff --git a/data/images/creatures/ghosttree/root-base-2.png b/data/images/creatures/ghosttree/root-base-2.png
new file mode 100644 (file)
index 0000000..6f99a5c
Binary files /dev/null and b/data/images/creatures/ghosttree/root-base-2.png differ
diff --git a/data/images/creatures/ghosttree/root-base-3.png b/data/images/creatures/ghosttree/root-base-3.png
new file mode 100644 (file)
index 0000000..055ba09
Binary files /dev/null and b/data/images/creatures/ghosttree/root-base-3.png differ
diff --git a/data/images/creatures/ghosttree/root-base.sprite b/data/images/creatures/ghosttree/root-base.sprite
new file mode 100644 (file)
index 0000000..edfa363
--- /dev/null
@@ -0,0 +1,22 @@
+(supertux-sprite
+  (action
+    (name "appearing")
+    (fps 16)
+    (images 
+      "root-base-0.png"
+      "root-base-1.png"
+      "root-base-2.png"
+      "root-base-3.png"
+    )
+  )
+  (action
+    (name "vanishing")
+    (fps 16)
+    (images 
+      "root-base-3.png"
+      "root-base-2.png"
+      "root-base-1.png"
+      "root-base-0.png"
+    )
+  )
+)
index 250e05e..5fb5c49 100644 (file)
@@ -122,7 +122,7 @@ GhostTree::active_update(float elapsed_time)
   if(root_timer.check()) {
     /* TODO indicate root with an animation */
     Player* player = get_nearest_player();
-    Root* root = new Root(Vector(player->get_bbox().get_left(), get_bbox().get_bottom()));
+    Root* root = new Root(Vector(player->get_bbox().get_left(), get_bbox().get_bottom()-64));
     Sector::current()->add_object(root);
   }
 }
index 4b94051..6fa949e 100644 (file)
 #include <config.h>
 
 #include "root.hpp"
+#include "sprite/sprite_manager.hpp"
 
-static const float SPEED = 5;
+static const float SPEED_GROW = 256;
+static const float SPEED_SHRINK = 128;
 
 Root::Root(const Vector& pos)
-  : BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_OBJECTS+20),
-    ypos(0), speed(-SPEED)
+  : BadGuy(pos, "images/creatures/ghosttree/root.sprite", LAYER_TILES-1),
+    mystate(STATE_APPEARING), offset_y(0)
 {
-  //ypos = sprite->get_height();
+  base_sprite.reset(sprite_manager->create("images/creatures/ghosttree/root-base.sprite"));
+  base_sprite->set_action("appearing", 1);
+  base_sprite->set_animation_loops(1); // TODO: necessary because set_action ignores loops for default action
+  physic.enable_gravity(false);
 }
 
 Root::~Root()
@@ -37,20 +42,49 @@ Root::~Root()
 void
 Root::activate()
 {
-  set_pos(start_position + Vector(0, ypos));
+  set_group(COLGROUP_TOUCHABLE);
+}
+
+void
+Root::deactivate()
+{
+  remove_me(); 
 }
 
 void
 Root::active_update(float elapsed_time)
 {
-  ypos += elapsed_time * speed;
-  if(ypos < 0) {
-    ypos = 0;
-    speed = -speed;
+  if (mystate == STATE_APPEARING) {  
+    if (base_sprite->animation_done()) mystate = STATE_GROWING;
+  }
+  else if (mystate == STATE_GROWING) {
+    offset_y -= elapsed_time * SPEED_GROW;
+    if (offset_y < -sprite->get_height()) {
+      offset_y = -sprite->get_height();
+      mystate = STATE_SHRINKING;
+    }
+    set_pos(start_position + Vector(0, offset_y));
   }
-  if(speed > 0 && ypos > sprite->get_height()) {
-    remove_me();
+  else if (mystate == STATE_SHRINKING) {
+    offset_y += elapsed_time * SPEED_SHRINK;
+    if (offset_y > 0) {
+      offset_y = 0;
+      mystate = STATE_VANISHING;
+      base_sprite->set_action("vanishing", 2);
+      base_sprite->set_animation_loops(2); // TODO: doesn't seem to work for loops=1 
+    }
+    set_pos(start_position + Vector(0, offset_y));
   }
-  set_pos(start_position + Vector(0, ypos));
+  else if (mystate == STATE_VANISHING) {
+    if (base_sprite->animation_done()) remove_me();
+  }
+  BadGuy::active_update(elapsed_time);
+}
+
+void
+Root::draw(DrawingContext& context)
+{
+  base_sprite->draw(context, start_position, LAYER_TILES+1);
+  if ((mystate != STATE_APPEARING) && (mystate != STATE_VANISHING)) BadGuy::draw(context);
 }
 
index 93d641e..32ec2fa 100644 (file)
@@ -19,6 +19,7 @@
 #ifndef __ROOT_H__
 #define __ROOT_H__
 
+#include <memory>
 #include "badguy.hpp"
 
 class Root : public BadGuy
@@ -28,11 +29,20 @@ public:
   ~Root();
 
   void activate();
+  void deactivate();
   void active_update(float elapsed_time);
+  virtual void draw(DrawingContext& context);
+  virtual bool is_flammable() const { return false; }
+  virtual bool is_freezable() const { return false; }
+  virtual void kill_fall() { }
 
-private:
-  float ypos;
-  float speed;
+protected:
+  enum MyState {
+    STATE_APPEARING, STATE_GROWING, STATE_SHRINKING, STATE_VANISHING
+  };
+  MyState mystate;
+  std::auto_ptr<Sprite> base_sprite;
+  float offset_y;
 };
 
 #endif