Removed Kirby badguy code, use simple sprite replacement in the level instead
[supertux.git] / src / badguy / owl.cpp
index db8b2fe..d7d2a53 100644 (file)
 
 #include "badguy/owl.hpp"
 
-#include "sprite/sprite.hpp"
-#include "supertux/object_factory.hpp"
-#include "supertux/sector.hpp"
+#include "audio/sound_manager.hpp"
 #include "object/anchor_point.hpp"
 #include "object/player.hpp"
 #include "object/rock.hpp"
+#include "sprite/sprite.hpp"
+#include "supertux/object_factory.hpp"
+#include "supertux/sector.hpp"
 #include "util/reader.hpp"
 #include "util/log.hpp"
 
@@ -49,27 +50,28 @@ Owl::Owl(const Vector& pos, Direction d) :
 void
 Owl::initialize()
 {
-  GameObject *game_object;
-
   physic.set_velocity_x(dir == LEFT ? -FLYING_SPEED : FLYING_SPEED);
   physic.enable_gravity(false);
   sprite->set_action(dir == LEFT ? "left" : "right");
 
-  game_object = ObjectFactory::instance().create(carried_obj_name, get_pos(), dir);
-  if (game_object == NULL) {
+  auto game_object = ObjectFactory::instance().create(carried_obj_name, get_pos(), dir);
+  if (game_object == NULL)
+  {
     log_fatal << "Creating \"" << carried_obj_name << "\" object failed." << std::endl;
-    return;
   }
-
-  carried_object = dynamic_cast<Portable *> (game_object);
-  if (carried_object == NULL) {
-    log_warning << "Object is not portable: " << carried_obj_name << std::endl;
-    delete game_object;
-    return;
+  else
+  {
+    carried_object = dynamic_cast<Portable*>(game_object.get());
+    if (carried_object == NULL)
+    {
+      log_warning << "Object is not portable: " << carried_obj_name << std::endl;
+    }
+    else
+    {
+      Sector::current()->add_object(game_object);
+    }
   }
-
-  Sector::current ()->add_object (game_object);
-} /* void initialize */
+}
 
 bool
 Owl::is_above_player (void)
@@ -98,13 +100,23 @@ Owl::active_update (float elapsed_time)
 {
   BadGuy::active_update (elapsed_time);
 
+  if(frozen)
+    return;
+
   if (carried_object != NULL) {
     if (!is_above_player ()) {
       Vector obj_pos = get_anchor_pos (bbox, ANCHOR_BOTTOM);
       obj_pos.x -= 16.0; /* FIXME: Actually do use the half width of the carried object here. */
       obj_pos.y += 3.0; /* Move a little away from the hitbox (the body). Looks nicer. */
 
-      carried_object->grab (*this, obj_pos, dir);
+      //To drop enemie before leave the screen
+      if (obj_pos.x<=16 || obj_pos.x+16>=Sector::current()->get_width()){
+        carried_object->ungrab (*this, dir);
+        carried_object = NULL;
+      }
+
+     else
+        carried_object->grab (*this, obj_pos, dir);
     }
     else { /* if (is_above_player) */
       carried_object->ungrab (*this, dir);
@@ -130,8 +142,57 @@ Owl::collision_squished(GameObject&)
 }
 
 void
+Owl::kill_fall()
+{
+  SoundManager::current()->play("sounds/fall.wav", get_pos());
+  physic.set_velocity_y(0);
+  physic.set_acceleration_y(0);
+  physic.enable_gravity(true);
+  set_state(STATE_FALLING);
+
+  if (carried_object != NULL) {
+    carried_object->ungrab (*this, dir);
+    carried_object = NULL;
+  }
+
+  // start dead-script
+  run_dead_script();
+}
+
+void
+Owl::freeze()
+{
+  if (carried_object != NULL) {
+    carried_object->ungrab (*this, dir);
+    carried_object = NULL;
+  }
+  physic.enable_gravity(true);
+  BadGuy::freeze();
+}
+
+void
+Owl::unfreeze()
+{
+  BadGuy::unfreeze();
+  physic.set_velocity_x(dir == LEFT ? -FLYING_SPEED : FLYING_SPEED);
+  physic.enable_gravity(false);
+  sprite->set_action(dir == LEFT ? "left" : "right");
+}
+
+bool
+Owl::is_freezable() const
+{
+  return true;
+}
+
+void
 Owl::collision_solid(const CollisionHit& hit)
 {
+  if(frozen)
+  {
+    BadGuy::collision_solid(hit);
+    return;
+  }
   if(hit.top || hit.bottom) {
     physic.set_velocity_y(0);
   } else if(hit.left || hit.right) {