New sounds: cracking, icecrash, pop, and sizzle.
[supertux.git] / src / badguy / mriceblock.cpp
index eed83fe..fa8e0ef 100644 (file)
@@ -19,6 +19,7 @@
 #include "audio/sound_manager.hpp"
 #include "object/player.hpp"
 #include "sprite/sprite.hpp"
+#include "sprite/sprite_manager.hpp"
 #include "supertux/object_factory.hpp"
 
 #include <math.h>
@@ -95,7 +96,6 @@ MrIceBlock::collision_solid(const CollisionHit& hit)
 
   if(hit.top || hit.bottom) { // floor or roof
     physic.set_velocity_y(0);
-    return;
   }
 
   // hit left or right
@@ -109,7 +109,7 @@ MrIceBlock::collision_solid(const CollisionHit& hit)
         sound_manager->play("sounds/iceblock_bump.wav", get_pos());
         physic.set_velocity_x(-physic.get_velocity_x()*.975);
       }
-      sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
+      this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1);
       if(fabsf(physic.get_velocity_x()) < walk_speed*1.5)
         set_state(ICESTATE_NORMAL);
       break;
@@ -134,10 +134,6 @@ MrIceBlock::collision(GameObject& object, const CollisionHit& hit)
 HitResponse
 MrIceBlock::collision_player(Player& player, const CollisionHit& hit)
 {
-  if(dir == UP) {
-    return FORCE_MOVE;
-  }
-
   // handle kicks from left or right side
   if(ice_state == ICESTATE_FLAT && get_state() == STATE_ACTIVE) {
     if(hit.left) {
@@ -228,33 +224,32 @@ MrIceBlock::collision_squished(GameObject& object)
 }
 
 void
-MrIceBlock::set_state(IceState state)
+MrIceBlock::set_state(IceState state, bool up)
 {
   if(ice_state == state)
     return;
 
   switch(state) {
     case ICESTATE_NORMAL:
+      this->set_action(dir == LEFT ? "left" : "right", /* loops = */ -1);
       WalkingBadguy::initialize();
       break;
     case ICESTATE_FLAT:
-      if(dir == UP) {
+      if(up) {
         physic.set_velocity_y(-KICKSPEED);
-        bbox.set_size(34, 31.8f);
       } else {
         sound_manager->play("sounds/stomp.wav", get_pos());
         physic.set_velocity_x(0);
         physic.set_velocity_y(0);
-
-        sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
       }
+      this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1);
       flat_timer.start(4);
       break;
     case ICESTATE_KICKED:
       sound_manager->play("sounds/kick.wav", get_pos());
 
       physic.set_velocity_x(dir == LEFT ? -KICKSPEED : KICKSPEED);
-      sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
+      this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1);
       // we should slide above 1 block holes now...
       bbox.set_size(34, 31.8f);
       break;
@@ -272,7 +267,7 @@ MrIceBlock::grab(MovingObject&, const Vector& pos, Direction dir)
 {
   movement = pos - get_pos();
   this->dir = dir;
-  sprite->set_action(dir == LEFT ? "flat-left" : "flat-right");
+  this->set_action(dir == LEFT ? "flat-left" : "flat-right", /* loops = */ -1);
   set_state(ICESTATE_GRABBED);
   set_colgroup_active(COLGROUP_DISABLED);
 }
@@ -280,8 +275,12 @@ MrIceBlock::grab(MovingObject&, const Vector& pos, Direction dir)
 void
 MrIceBlock::ungrab(MovingObject& , Direction dir)
 {
-  this->dir = dir;
-  set_state(dir == UP ? ICESTATE_FLAT : ICESTATE_KICKED);
+  if(dir == UP) {
+    set_state(ICESTATE_FLAT, true);
+  } else {
+    this->dir = dir;
+    set_state(ICESTATE_KICKED);
+  }
   set_colgroup_active(COLGROUP_MOVING);
 }
 
@@ -291,4 +290,11 @@ MrIceBlock::is_portable() const
   return ice_state == ICESTATE_FLAT;
 }
 
+SmartBlock::SmartBlock(const Reader& reader) :
+  MrIceBlock(reader)
+{
+  max_drop_height = 16;
+  sprite = sprite_manager->create("images/creatures/mr_iceblock/smart_block/smart_block.sprite");
+}
+
 /* EOF */