Shrunk cherry bomb a little, fixed bounding boxes. /
[supertux.git] / src / badguy / mriceblock.cpp
index 3361f41..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);
-  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)
-  : 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;
-  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
@@ -52,6 +57,7 @@ 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);
 
@@ -67,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
@@ -228,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);