Remove bogus assert
[supertux.git] / src / object / icecrusher.cpp
index 58f3376..72220a4 100644 (file)
@@ -41,7 +41,7 @@ const float PAUSE_TIME_LARGE  = 1.0;
 
 IceCrusher::IceCrusher(const Reader& reader) :
   MovingSprite(reader, "images/creatures/icecrusher/icecrusher.sprite", LAYER_OBJECTS, COLGROUP_STATIC),
-  state(IDLE), 
+  state(IDLE),
   start_position(),
   physic(),
   cooldown_timer(0.0),
@@ -52,37 +52,37 @@ IceCrusher::IceCrusher(const Reader& reader) :
 {
   // TODO: icecrusher hitting deserves its own sounds-
   // one for hitting the ground, one for hitting Tux
-  sound_manager->preload("sounds/brick.wav");
+  SoundManager::current()->preload("sounds/brick.wav");
 
   start_position = get_bbox().p1;
   set_state(state, true);
-  
+
   float sprite_width = sprite->get_width ();
   if (sprite_width >= 128.0)
     ic_size = LARGE;
 
-  lefteye = sprite_manager->create(sprite_name);
+  lefteye = SpriteManager::current()->create(sprite_name);
   lefteye->set_action("lefteye");
-  righteye = sprite_manager->create(sprite_name);
+  righteye = SpriteManager::current()->create(sprite_name);
   righteye->set_action("righteye");
-  whites = sprite_manager->create(sprite_name);
+  whites = SpriteManager::current()->create(sprite_name);
   whites->set_action("whites");
 }
 
 /*
   IceCrusher::IceCrusher(const IceCrusher& other)
-  : MovingSprite(other), 
-  state(other.state), speed(other.speed) 
+  : MovingSprite(other),
+  state(other.state), speed(other.speed)
   {
   start_position = get_bbox().p1;
   set_state(state, true);
   }
 */
-void 
-IceCrusher::set_state(IceCrusherState state, bool force) 
+void
+IceCrusher::set_state(IceCrusherState state_, bool force)
 {
-  if ((this->state == state) && (!force)) return;
-  switch(state) {
+  if ((this->state == state_) && (!force)) return;
+  switch(state_) {
     case IDLE:
       set_group(COLGROUP_STATIC);
       physic.enable_gravity (false);
@@ -103,7 +103,7 @@ IceCrusher::set_state(IceCrusherState state, bool force)
       log_debug << "IceCrusher in invalid state" << std::endl;
       break;
   }
-  this->state = state;
+  this->state = state_;
 }
 
 HitResponse
@@ -114,7 +114,7 @@ IceCrusher::collision(GameObject& other, const CollisionHit& hit)
   /* If the other object is the player, and the collision is at the bottom of
    * the ice crusher, hurt the player. */
   if (player && hit.bottom) {
-    sound_manager->play("sounds/brick.wav");
+    SoundManager::current()->play("sounds/brick.wav");
     if(player->is_invincible()) {
       if (state == CRUSHING)
         set_state(RECOVERING);
@@ -131,8 +131,8 @@ IceCrusher::collision(GameObject& other, const CollisionHit& hit)
   }
   return FORCE_MOVE;
 }
-    
-void 
+
+void
 IceCrusher::collision_solid(const CollisionHit& hit)
 {
   switch(state) {
@@ -143,35 +143,35 @@ IceCrusher::collision_solid(const CollisionHit& hit)
         if (ic_size == LARGE) {
           cooldown_timer = PAUSE_TIME_LARGE;
           Sector::current()->camera->shake (/* frequency = */ .125f, /* x = */ 0.0, /* y = */ 16.0);
-          sound_manager->play("sounds/brick.wav");
+          SoundManager::current()->play("sounds/brick.wav");
           // throw some particles, bigger and more for large icecrusher
           for(int j = 0; j < 9; j++)
           {
-          Sector::current()->add_object(
-            new Particles(Vector(get_bbox().p2.x - j*8 - 4, get_bbox().p2.y),
-              0, 90-5*j, Vector(140, -380), Vector(0, 300),
-              1, Color(.6f, .6f, .6f), 5, 1.8f, LAYER_OBJECTS+1));
-          Sector::current()->add_object(
-            new Particles(Vector(get_bbox().p1.x + j*8 + 4, get_bbox().p2.y),
-              270+5*j, 360, Vector(140, -380), Vector(0, 300),
-              1, Color(.6f, .6f, .6f), 5, 1.8f, LAYER_OBJECTS+1));
+          Sector::current()->add_object(std::make_shared<Particles>(
+                                          Vector(get_bbox().p2.x - j*8 - 4, get_bbox().p2.y),
+                                          0, 90-5*j, 140, 380, Vector(0, 300),
+                                          1, Color(.6f, .6f, .6f), 5, 1.8f, LAYER_OBJECTS+1));
+          Sector::current()->add_object(std::make_shared<Particles>(
+                                          Vector(get_bbox().p1.x + j*8 + 4, get_bbox().p2.y),
+                                          270+5*j, 360, 140, 380, Vector(0, 300),
+                                          1, Color(.6f, .6f, .6f), 5, 1.8f, LAYER_OBJECTS+1));
           }
         }
         else {
           cooldown_timer = PAUSE_TIME_NORMAL;
           Sector::current()->camera->shake (/* frequency = */ .1f, /* x = */ 0.0, /* y = */ 8.0);
-          sound_manager->play("sounds/brick.wav");
+          SoundManager::current()->play("sounds/brick.wav");
           // throw some particles
           for(int j = 0; j < 5; j++)
           {
-          Sector::current()->add_object(
-            new Particles(Vector(get_bbox().p2.x - j*8 - 4, get_bbox().p2.y),
-              0, 90+10*j, Vector(140, -260), Vector(0, 300),
-              1, Color(.6f, .6f, .6f), 4, 1.6f, LAYER_OBJECTS+1));
-          Sector::current()->add_object(
-            new Particles(Vector(get_bbox().p1.x + j*8 + 4, get_bbox().p2.y),
-              270+10*j, 360, Vector(140, -260), Vector(0, 300),
-              1, Color(.6f, .6f, .6f), 4, 1.6f, LAYER_OBJECTS+1));
+          Sector::current()->add_object(std::make_shared<Particles>(
+                                          Vector(get_bbox().p2.x - j*8 - 4, get_bbox().p2.y),
+                                          0, 90+10*j, 140, 260, Vector(0, 300),
+                                          1, Color(.6f, .6f, .6f), 4, 1.6f, LAYER_OBJECTS+1));
+          Sector::current()->add_object(std::make_shared<Particles>(
+                                          Vector(get_bbox().p1.x + j*8 + 4, get_bbox().p2.y),
+                                          270+10*j, 360, 140, 260, Vector(0, 300),
+                                          1, Color(.6f, .6f, .6f), 4, 1.6f, LAYER_OBJECTS+1));
           }
         }
         set_state(RECOVERING);
@@ -238,14 +238,14 @@ IceCrusher::draw(DrawingContext& context)
 {
   context.push_target();
   context.set_target(DrawingContext::NORMAL);
-  sprite->draw(context, get_pos(), layer);
+  sprite->draw(context, get_pos(), layer+2);
   if(!(state == CRUSHING) && sprite->has_action("whites"))
   {
     // draw icecrusher's eyes slightly behind
-    lefteye->draw(context, get_pos()+eye_position(false), layer-1);
-    righteye->draw(context, get_pos()+eye_position(true), layer-1);
+    lefteye->draw(context, get_pos()+eye_position(false), layer+1);
+    righteye->draw(context, get_pos()+eye_position(true), layer+1);
     // draw the whites of icecrusher's eyes even further behind
-    whites->draw(context, get_pos(), layer-2);
+    whites->draw(context, get_pos(), layer);
   }
   context.pop_target();
 }
@@ -287,7 +287,7 @@ IceCrusher::eye_position(bool right)
       const float displacement_y = player_focus_y - crusher_origin_y;
       const float displacement_mag = pow(pow(displacement_x, 2.0) + pow(displacement_y, 2.0), 0.5);
       // Determine weighting for eye displacement along x given icecrusher eye shape
-      int weight_x = sprite->get_width()/64 * ((displacement_x > 0) == right) ? 1 : 4;
+      int weight_x = sprite->get_width()/64 * (((displacement_x > 0) == right) ? 1 : 4);
       int weight_y = sprite->get_width()/64 * 2;
 
       return Vector(displacement_x/displacement_mag * weight_x, displacement_y/displacement_mag * weight_y - weight_y);