some new GhostTree stuff
authorChristoph Sommer <mail@christoph-sommer.de>
Sat, 26 May 2007 18:50:16 +0000 (18:50 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Sat, 26 May 2007 18:50:16 +0000 (18:50 +0000)
SVN-Revision: 5035

data/images/creatures/ghosttree/ghosttree-dying-0.png [new file with mode: 0644]
data/images/creatures/ghosttree/ghosttree-glow-dying-0.png [new file with mode: 0644]
data/images/creatures/ghosttree/ghosttree-glow.png [new file with mode: 0644]
data/images/creatures/ghosttree/ghosttree-glow.sprite [new file with mode: 0644]
data/images/creatures/ghosttree/ghosttree.sprite
src/badguy/ghosttree.cpp
src/badguy/ghosttree.hpp
src/badguy/treewillowisp.cpp
src/badguy/treewillowisp.hpp

diff --git a/data/images/creatures/ghosttree/ghosttree-dying-0.png b/data/images/creatures/ghosttree/ghosttree-dying-0.png
new file mode 100644 (file)
index 0000000..cc97d00
Binary files /dev/null and b/data/images/creatures/ghosttree/ghosttree-dying-0.png differ
diff --git a/data/images/creatures/ghosttree/ghosttree-glow-dying-0.png b/data/images/creatures/ghosttree/ghosttree-glow-dying-0.png
new file mode 100644 (file)
index 0000000..b0d8aaa
Binary files /dev/null and b/data/images/creatures/ghosttree/ghosttree-glow-dying-0.png differ
diff --git a/data/images/creatures/ghosttree/ghosttree-glow.png b/data/images/creatures/ghosttree/ghosttree-glow.png
new file mode 100644 (file)
index 0000000..5b9ff86
Binary files /dev/null and b/data/images/creatures/ghosttree/ghosttree-glow.png differ
diff --git a/data/images/creatures/ghosttree/ghosttree-glow.sprite b/data/images/creatures/ghosttree/ghosttree-glow.sprite
new file mode 100644 (file)
index 0000000..0ec4634
--- /dev/null
@@ -0,0 +1,18 @@
+(supertux-sprite
+  (action
+    (name "default")
+    (images 
+      "ghosttree-glow.png"
+    )
+  )
+  (action
+    (name "dying")
+    (fps 4)
+    (images 
+      "ghosttree-glow-dying-0.png"
+      "ghosttree-glow-dying-0.png"
+      "ghosttree-glow-dying-0.png"
+      "ghosttree-glow-dying-0.png"
+    )
+  )
+)
index 7cb2464..fc57556 100644 (file)
@@ -5,4 +5,14 @@
       "ghosttree.png"
     )
   )
+  (action
+    (name "dying")
+    (fps 4)
+    (images 
+      "ghosttree-dying-0.png"
+      "ghosttree-dying-0.png"
+      "ghosttree-dying-0.png"
+      "ghosttree-dying-0.png"
+    )
+  )
 )
index 5fb5c49..b916b57 100644 (file)
 
 #include "ghosttree.hpp"
 #include "treewillowisp.hpp"
+#include "sprite/sprite_manager.hpp"
 #include "root.hpp"
+#include "random_generator.hpp"
 
 static const size_t WILLOWISP_COUNT = 10;
+static const float ROOT_TOP_OFFSET = -64;
+static const Vector SUCK_TARGET_OFFSET = Vector(-32,72);
+static const float SUCK_TARGET_SPREAD = 16;
 
 GhostTree::GhostTree(const lisp::Lisp& lisp)
   : BadGuy(lisp, "images/creatures/ghosttree/ghosttree.sprite",
@@ -30,6 +35,7 @@ GhostTree::GhostTree(const lisp::Lisp& lisp)
     willo_spawn_y(0), willo_radius(200), willo_speed(1.8f), willo_color(0),
     treecolor(0)
 {
+  glow_sprite.reset(sprite_manager->create("images/creatures/ghosttree/ghosttree-glow.sprite"));
 }
 
 GhostTree::~GhostTree()
@@ -37,6 +43,19 @@ GhostTree::~GhostTree()
 }
 
 void
+GhostTree::die()
+{
+  sprite->set_action("dying", 1); 
+  glow_sprite->set_action("dying", 1); 
+
+  std::vector<TreeWillOWisp*>::iterator iter;
+  for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) {
+    TreeWillOWisp *willo = *iter;
+    willo->vanish();
+  }
+}
+
+void
 GhostTree::activate()
 {
   willowisp_timer.start(1.0f, true);
@@ -65,17 +84,17 @@ GhostTree::active_update(float elapsed_time)
     case 5: col = Color(0, 1, 1); break;
     default: assert(false);
     }
-    sprite->set_color(col);
+    glow_sprite->set_color(col);
   }
 
   if(suck_timer.check()) {
-    Color col = sprite->get_color();
+    Color col = glow_sprite->get_color();
     sound_manager->play("sounds/tree_suck.ogg", get_pos());
     std::vector<TreeWillOWisp*>::iterator iter;
     for(iter = willowisps.begin(); iter != willowisps.end(); ++iter) {
       TreeWillOWisp *willo = *iter;
       if(willo->get_color() == col) {
-        willo->start_sucking();
+        willo->start_sucking(get_bbox().get_middle() + SUCK_TARGET_OFFSET + Vector(systemRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD), systemRandom.randf(-SUCK_TARGET_SPREAD, SUCK_TARGET_SPREAD)));
       }
     }
   }
@@ -122,7 +141,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()-64));
+    Root* root = new Root(Vector(player->get_bbox().get_left(), get_bbox().get_bottom()+ROOT_TOP_OFFSET));
     Sector::current()->add_object(root);
   }
 }
@@ -133,5 +152,17 @@ GhostTree::willowisp_died(TreeWillOWisp *willowisp)
   willowisps.erase(std::find(willowisps.begin(), willowisps.end(), willowisp));
 }
 
+void
+GhostTree::draw(DrawingContext& context)
+{
+  BadGuy::draw(context);
+
+  context.push_target();
+  context.set_target(DrawingContext::LIGHTMAP);
+  glow_sprite->draw(context, get_pos(), layer);
+  context.pop_target();
+}
+
+
 IMPLEMENT_FACTORY(GhostTree, "ghosttree");
 
index d451c38..c17792b 100644 (file)
@@ -33,6 +33,9 @@ public:
   void activate();
   void active_update(float elapsed_time);
   void willowisp_died(TreeWillOWisp* willowisp);
+  virtual void draw(DrawingContext& context);
+
+  void die();
 
 private:
   Timer willowisp_timer;
@@ -41,6 +44,7 @@ private:
   float willo_speed;
   int   willo_color;
 
+  std::auto_ptr<Sprite> glow_sprite;
   Timer colorchange_timer;
   Timer suck_timer;
   Timer root_timer;
index c143406..36d798e 100644 (file)
@@ -66,9 +66,10 @@ TreeWillOWisp::vanish()
 }
 
 void
-TreeWillOWisp::start_sucking()
+TreeWillOWisp::start_sucking(Vector suck_target)
 {
   mystate = STATE_SUCKED;
+  this->suck_target = suck_target;
 }
 
 HitResponse
@@ -102,7 +103,7 @@ TreeWillOWisp::active_update(float elapsed_time)
   }
 
   if (mystate == STATE_SUCKED) {
-    Vector dir = tree->get_bbox().get_middle() - get_pos();
+    Vector dir = suck_target - get_pos();
     if(dir.norm() < 5) {
       vanish();
       return;
index 58805e4..60fac85 100644 (file)
@@ -37,7 +37,7 @@ public:
    * make TreeWillOWisp vanish
    */
   void vanish();
-  void start_sucking();
+  void start_sucking(Vector suck_target);
 
   void active_update(float elapsed_time);
   void set_color(const Color& color);
@@ -65,6 +65,8 @@ private:
   std::auto_ptr<SoundSource> sound_source;
   Vector     treepos_delta;
   GhostTree* tree;
+
+  Vector suck_target;
 };
 
 #endif