translation update
[supertux.git] / src / badguy / mole.cpp
index 1391d2a..fd66012 100644 (file)
 
 #include <math.h>
 
-static const float IDLE_TIME = 0.2f; /**< time to wait before and after throwing */
+static const float MOLE_WAIT_TIME = 0.2f; /**< time to wait before and after throwing */
 static const float THROW_TIME = 4.6f; /**< time to spend throwing */
 static const float THROW_INTERVAL = 1; /**< time between two thrown rocks */
 static const float THROW_VELOCITY = 400; /**< initial velocity of thrown rocks */
 
 Mole::Mole(const Reader& reader) :
-  BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1), 
+  BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1),
   state(PRE_THROWING),
   timer(),
   throw_timer()
 {
   physic.enable_gravity(false);
-  sound_manager->preload("sounds/fall.wav");
-  sound_manager->preload("sounds/squish.wav");
-  sound_manager->preload("sounds/dartfire.wav");
+  SoundManager::current()->preload("sounds/fall.wav");
+  SoundManager::current()->preload("sounds/squish.wav");
+  SoundManager::current()->preload("sounds/dartfire.wav");
 }
 
 Mole::Mole(const Vector& pos) :
-  BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1), 
+  BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1),
   state(PRE_THROWING),
   timer(),
   throw_timer()
 {
   physic.enable_gravity(false);
-  sound_manager->preload("sounds/fall.wav");
-  sound_manager->preload("sounds/squish.wav");
-  sound_manager->preload("sounds/dartfire.wav");
+  SoundManager::current()->preload("sounds/fall.wav");
+  SoundManager::current()->preload("sounds/squish.wav");
+  SoundManager::current()->preload("sounds/dartfire.wav");
 }
 
 void
@@ -63,7 +63,7 @@ void
 Mole::kill_fall()
 {
   set_state(DEAD);
-  sound_manager->play("sounds/fall.wav", get_pos());
+  SoundManager::current()->play("sounds/fall.wav", get_pos());
   run_dead_script();
 }
 
@@ -76,8 +76,11 @@ Mole::collision_badguy(BadGuy& , const CollisionHit& )
 bool
 Mole::collision_squished(GameObject& )
 {
+  if (frozen)
+    return true;
+
   set_state(DEAD);
-  sound_manager->play("sounds/squish.wav", get_pos());
+  SoundManager::current()->play("sounds/squish.wav", get_pos());
   run_dead_script();
   return true;
 }
@@ -88,12 +91,12 @@ Mole::throw_rock()
   float px = get_bbox().get_middle().x;
   float py = get_bbox().get_middle().y;
 
-  float angle = systemRandom.rand(90 - 15, 90 + 15) * (M_PI / 180);
+  float angle = gameRandom.rand(90 - 15, 90 + 15) * (M_PI / 180);
   float vx = cos(angle) * THROW_VELOCITY;
   float vy = -sin(angle) * THROW_VELOCITY;
 
-  sound_manager->play("sounds/dartfire.wav", get_pos());
-  Sector::current()->add_object(new MoleRock(Vector(px, py), Vector(vx, vy), this));
+  SoundManager::current()->play("sounds/dartfire.wav", get_pos());
+  Sector::current()->add_object(std::make_shared<MoleRock>(Vector(px, py), Vector(vx, vy), this));
 }
 
 void
@@ -101,6 +104,9 @@ Mole::active_update(float elapsed_time)
 {
   BadGuy::active_update(elapsed_time);
 
+  if (frozen)
+    return;
+
   switch (state) {
     case PRE_THROWING:
       if (timer.check()) {
@@ -132,14 +138,23 @@ Mole::active_update(float elapsed_time)
 
 }
 
+bool
+Mole::is_freezable() const
+{
+  return true;
+}
+
 void
 Mole::set_state(MoleState new_state)
 {
+  if (frozen)
+    return;
+
   switch (new_state) {
     case PRE_THROWING:
       sprite->set_action("idle");
       set_colgroup_active(COLGROUP_DISABLED);
-      timer.start(IDLE_TIME);
+      timer.start(MOLE_WAIT_TIME);
       break;
     case THROWING:
       sprite->set_action("idle");
@@ -150,7 +165,7 @@ Mole::set_state(MoleState new_state)
     case POST_THROWING:
       sprite->set_action("idle");
       set_colgroup_active(COLGROUP_DISABLED);
-      timer.start(IDLE_TIME);
+      timer.start(MOLE_WAIT_TIME);
       break;
     case PEEKING:
       sprite->set_action("peeking", 1);
@@ -165,6 +180,4 @@ Mole::set_state(MoleState new_state)
   state = new_state;
 }
 
-IMPLEMENT_FACTORY(Mole, "mole");
-
 /* EOF */