Fixed sprite, bounding-boxes and behaviour of Mr. Tree
authorChristoph Sommer <mail@christoph-sommer.de>
Thu, 16 Mar 2006 20:08:43 +0000 (20:08 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Thu, 16 Mar 2006 20:08:43 +0000 (20:08 +0000)
SVN-Revision: 3095

data/images/creatures/mr_tree/mr_tree.sprite
data/images/creatures/mr_tree/squished-left.png
src/badguy/mrtree.cpp
src/badguy/mrtree.hpp

index e18e1e4..e6359bb 100644 (file)
@@ -16,7 +16,8 @@
   (mirror-action "large-left")
  )
  (action
-  (y-offset 12)
+  (x-offset 20)
+  (y-offset 23)
   (name "small-left")
   (images "small-left-1.png"
           "small-left-2.png"
 )
  )
   (action
-   (y-offset 12)
+   (x-offset 20)
+   (y-offset 23)
    (name "small-right")
    (mirror-action "small-left")
   )
   (action
-   (y-offset )
+   (x-offset 20)
+   (y-offset 23)
    (name "squished-left")
    (images "squished-left.png")
   )
   (action
-   (y-offset )
+   (x-offset 20)
+   (y-offset 23)
    (name "squished-right")
    (mirror-action "squished-left")
   )
index 4d362a6..44b59b3 100644 (file)
Binary files a/data/images/creatures/mr_tree/squished-left.png and b/data/images/creatures/mr_tree/squished-left.png differ
index 028d7f4..1288a93 100644 (file)
@@ -23,7 +23,8 @@
 #include "mrtree.hpp"
 
 static const float WALKSPEED = 100;
-static const float WALKSPEED_SMALL =120;
+static const float WALKSPEED_SMALL = 120;
+static const float INVINCIBLE_TIME = 1;
 
 MrTree::MrTree(const lisp::Lisp& reader)
   : mystate(STATE_BIG)
@@ -50,13 +51,15 @@ MrTree::write(lisp::Writer& writer)
 void
 MrTree::activate()
 {
-  if(mystate == STATE_BIG) {
+  if (mystate == STATE_BIG) {
     physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
     sprite->set_action(dir == LEFT ? "large-left" : "large-right");
-  } else {
+    return;
+  }
+  if (mystate == STATE_NORMAL) {
     physic.set_velocity_x(dir == LEFT ? -WALKSPEED_SMALL : WALKSPEED_SMALL);
-    bbox.set_size(31.8, 31.8);
     sprite->set_action(dir == LEFT ? "small-left" : "small-right");
+    return;
   }
 }
 
@@ -66,8 +69,7 @@ MrTree::active_update(float elapsed_time)
   if (stay_on_platform && may_fall_off_platform())
   {
     dir = (dir == LEFT ? RIGHT : LEFT);
-    sprite->set_action(dir == LEFT ? "large-left" : "large-right");
-    physic.set_velocity_x(-physic.get_velocity_x());
+    activate();
   }
 
   BadGuy::active_update(elapsed_time);
@@ -76,21 +78,37 @@ MrTree::active_update(float elapsed_time)
 bool
 MrTree::collision_squished(Player& player)
 {
+  // if we're big, we shrink
   if(mystate == STATE_BIG) {
     mystate = STATE_NORMAL;
     activate();
 
-  
+    // shrink bounding box and adjust sprite position to where the stump once was
+    bbox.set_size(42, 62);
+    Vector pos = get_pos();
+    pos.x += 20;
+    pos.y += 23;
+    set_pos(pos);
+
     sound_manager->play("sounds/mr_tree.ogg", get_pos());
     player.bounce(*this);
-  } else {
-bbox.set_size(67.8, 99.8);
-sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
-sound_manager->play("sounds/mr_treehit.ogg", get_pos());
-player.bounce(*this);
-   
+
+    invincible_timer.start(INVINCIBLE_TIME);
+
+    return true;
   }
-  
+
+  // if we're small, but still invincible, we ignore the hit
+  if (!invincible_timer.check()) {
+    sound_manager->play("sounds/mr_treehit.ogg", get_pos());
+    player.bounce(*this);
+    return true;
+  }
+
+  // if we're small and no longer invincible, we die
+  sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
+  bbox.set_size(42, 42);
+  kill_squished(player);
   return true;
 }
 
index 93463f7..fd2aebb 100644 (file)
@@ -41,6 +41,8 @@ protected:
   MyState mystate;
   bool stay_on_platform;
 
+  Timer invincible_timer;
+
   bool collision_squished(Player& player);
 };