Added a warning message alerting that a badguy included in level stats has left the...
[supertux.git] / src / badguy / owl.cpp
index 011a527..f379153 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"
 
@@ -31,7 +32,7 @@
 
 Owl::Owl(const Reader& reader) :
   BadGuy(reader, "images/creatures/owl/owl.sprite", LAYER_OBJECTS + 1),
-  carried_obj_name("bombfish"),
+  carried_obj_name("skydive"),
   carried_object(NULL)
 {
   reader.get("carry", carried_obj_name);
@@ -40,7 +41,7 @@ Owl::Owl(const Reader& reader) :
 
 Owl::Owl(const Vector& pos, Direction d) :
   BadGuy(pos, d, "images/creatures/owl/owl.sprite", LAYER_OBJECTS + 1),
-  carried_obj_name("bombfish"),
+  carried_obj_name("skydive"),
   carried_object(NULL)
 {
   set_action (dir == LEFT ? "left" : "right", /* loops = */ -1);
@@ -104,7 +105,14 @@ Owl::active_update (float elapsed_time)
       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,6 +138,24 @@ Owl::collision_squished(GameObject&)
 }
 
 void
+Owl::kill_fall()
+{
+  sound_manager->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::collision_solid(const CollisionHit& hit)
 {
   if(hit.top || hit.bottom) {
@@ -137,10 +163,12 @@ Owl::collision_solid(const CollisionHit& hit)
   } else if(hit.left || hit.right) {
     if (dir == LEFT) {
       set_action ("right", /* loops = */ -1);
+      dir = RIGHT;
       physic.set_velocity_x (FLYING_SPEED);
     }
     else {
       set_action ("left", /* loops = */ -1);
+      dir = LEFT;
       physic.set_velocity_x (-FLYING_SPEED);
     }
   }