Shrunk cherry bomb a little, fixed bounding boxes. /
[supertux.git] / src / badguy / mriceblock.cpp
index 8ec6f9a..ca0431a 100644 (file)
 #include "mriceblock.hpp"
 #include "object/block.hpp"
 
-static const float WALKSPEED = 80;
-static const float KICKSPEED = 500;
-static const int MAXSQUISHES = 10;
+namespace {
+  const float WALKSPEED = 80;
+  const float KICKSPEED = 500;
+  const int MAXSQUISHES = 10;
+}
 
 MrIceBlock::MrIceBlock(const lisp::Lisp& reader)
-  : ice_state(ICESTATE_NORMAL), squishcount(0)
+  : BadGuy(reader, "images/creatures/mr_iceblock/mr_iceblock.sprite"), ice_state(ICESTATE_NORMAL), squishcount(0)
 {
-  reader.get("x", start_position.x);
-  reader.get("y", start_position.y);
-  stay_on_platform = false;
-  reader.get("stay-on-platform", stay_on_platform);
-  bbox.set_size(31.8, 31.8);
-  sprite = sprite_manager->create("images/creatures/mr_iceblock/mr_iceblock.sprite");
+  reader.get("direction", direction);
   set_direction = false;
+  if( direction != "auto" && direction != ""){
+    set_direction = true;
+    initial_direction = str2dir( direction );
+  }
+  sound_manager->preload("sounds/iceblock_bump.wav");
+  sound_manager->preload("sounds/stomp.wav");
+  sound_manager->preload("sounds/kick.wav");
 }
 
-MrIceBlock::MrIceBlock(float pos_x, float pos_y, Direction d, bool stay_on_plat = false )
-  : ice_state(ICESTATE_NORMAL), squishcount(0)
+MrIceBlock::MrIceBlock(const Vector& pos, Direction d)
+  : BadGuy(pos, "images/creatures/mr_iceblock/mr_iceblock.sprite"), ice_state(ICESTATE_NORMAL), squishcount(0)
 {
-  start_position.x = pos_x;
-  start_position.y = pos_y;
-  stay_on_platform = stay_on_plat;
-  bbox.set_size(31.8, 31.8);
-  sprite = sprite_manager->create("images/creatures/mr_iceblock/mr_iceblock.sprite");
   set_direction = true;
   initial_direction = d;
+  sound_manager->preload("sounds/iceblock_bump.wav");
+  sound_manager->preload("sounds/stomp.wav");
+  sound_manager->preload("sounds/kick.wav");
 }
 
 void
@@ -55,9 +57,9 @@ MrIceBlock::write(lisp::Writer& writer)
 {
   writer.start_list("mriceblock");
 
+  writer.write_string("direction", direction);
   writer.write_float("x", start_position.x);
   writer.write_float("y", start_position.y);
-  writer.write_bool("stay-on-platform", stay_on_platform);
 
   writer.end_list("mriceblock");
 }
@@ -71,6 +73,7 @@ MrIceBlock::activate()
 
   physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
   sprite->set_action(dir == LEFT ? "left" : "right");
+  set_state(ICESTATE_NORMAL);
 }
 
 void
@@ -83,9 +86,7 @@ MrIceBlock::active_update(float elapsed_time)
     set_state(ICESTATE_NORMAL);
   }
 
-  if (ice_state == ICESTATE_NORMAL &&
-      stay_on_platform &&
-      may_fall_off_platform())
+  if (ice_state == ICESTATE_NORMAL && might_fall(601))
   {
     dir = (dir == LEFT ? RIGHT : LEFT);
     sprite->set_action(dir == LEFT ? "left" : "right");
@@ -234,10 +235,6 @@ MrIceBlock::set_state(IceState state)
   else
     flags &= ~FLAG_PORTABLE;
 
-  if(ice_state == ICESTATE_KICKED) {
-    bbox.set_size(31.8, 31.8);
-  }
-
   switch(state) {
     case ICESTATE_NORMAL:
       physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
@@ -276,7 +273,6 @@ MrIceBlock::grab(MovingObject&, const Vector& pos, Direction dir)
   sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
   set_state(ICESTATE_GRABBED);
   set_group(COLGROUP_DISABLED);
-  remove_out_of_bounds = false;
 }
 
 void
@@ -285,7 +281,6 @@ MrIceBlock::ungrab(MovingObject& , Direction dir)
   this->dir = dir;
   set_state(ICESTATE_KICKED);
   set_group(COLGROUP_MOVING);
-  remove_out_of_bounds = true;
 }
 
 IMPLEMENT_FACTORY(MrIceBlock, "mriceblock")