Owl: Let go of the carried object when above Tux.
authorflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sat, 6 Mar 2010 17:02:19 +0000 (17:02 +0000)
committerflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sat, 6 Mar 2010 17:02:19 +0000 (17:02 +0000)
git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6562 837edb03-e0f3-0310-88ca-d4d4e8b29345

src/badguy/owl.cpp
src/badguy/owl.hpp

index 6389f71..5677ef0 100644 (file)
@@ -20,6 +20,7 @@
 #include "sprite/sprite.hpp"
 #include "supertux/object_factory.hpp"
 #include "supertux/sector.hpp"
+#include "object/player.hpp"
 #include "object/rock.hpp"
 #include "util/reader.hpp"
 #include "util/log.hpp"
@@ -68,26 +69,54 @@ Owl::initialize()
   Sector::current ()->add_object (game_object);
 } /* void initialize */
 
+bool
+Owl::is_above_player (void)
+{
+  Player* player = Sector::current()->get_nearest_player (this->get_bbox ());
+  if (!player)
+    return false;
+
+  const Rectf& player_bbox = player->get_bbox();
+  const Rectf& owl_bbox = get_bbox();
+  if ((player_bbox.p1.y >= owl_bbox.p2.y) /* player is below us */
+      && (player_bbox.p2.x > owl_bbox.p1.x)
+      && (player_bbox.p1.x < owl_bbox.p2.x))
+    return true;
+  else
+    return false;
+}
+
 void
 Owl::active_update (float elapsed_time)
 {
   BadGuy::active_update (elapsed_time);
 
   if (carried_object != NULL) {
-    Vector obj_pos = get_pos ();
-    
-    obj_pos.y += bbox.get_height ();
-    carried_object->grab (*this, obj_pos, dir);
+    if (!is_above_player ()) {
+      Vector obj_pos = get_pos ();
+
+      obj_pos.y += bbox.get_height ();
+      carried_object->grab (*this, obj_pos, dir);
+    }
+    else { /* if (is_above_player) */
+      carried_object->ungrab (*this, dir);
+      carried_object = NULL;
+    }
   }
 }
 
 bool
 Owl::collision_squished(GameObject&)
 {
+  Player* player = Sector::current()->get_nearest_player (this->get_bbox ());
+  if (player)
+    player->bounce (*this);
+
   if (carried_object != NULL) {
     carried_object->ungrab (*this, dir);
     carried_object = NULL;
   }
+
   kill_fall ();
   return true;
 }
index 7510cae..64a7640 100644 (file)
@@ -31,6 +31,7 @@ public:
   void collision_solid(const CollisionHit& hit);
 
 protected:
+  bool is_above_player (void);
   void active_update (float elapsed_time);
   bool collision_squished(GameObject& object);
   HitResponse collision_player(Player& player, const CollisionHit& hit);