Owl: Add an offset to the "is_above_player()" method.
authorflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sat, 6 Mar 2010 17:16:38 +0000 (17:16 +0000)
committerflorianf <florianf@837edb03-e0f3-0310-88ca-d4d4e8b29345>
Sat, 6 Mar 2010 17:16:38 +0000 (17:16 +0000)
This way it is more likely that the thrown object will hit Tux. Also, the
standard "collision_player()" method from BadGuy will be used. There's no need
for the hack copied from the "Kamikaze Snowball".

git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6563 837edb03-e0f3-0310-88ca-d4d4e8b29345

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

index 5677ef0..a110b23 100644 (file)
@@ -26,6 +26,7 @@
 #include "util/log.hpp"
 
 #define FLYING_SPEED 120.0
+#define ACTIVATION_DISTANCE 128.0
 
 Owl::Owl(const Reader& reader) :
   BadGuy(reader, "images/creatures/owl/owl.sprite"),
@@ -76,11 +77,16 @@ Owl::is_above_player (void)
   if (!player)
     return false;
 
+  /* Let go of carried objects a short while *before* Tux is below us. This
+   * makes it more likely that we'll hit him. */
+  float x_offset = (dir == LEFT) ? ACTIVATION_DISTANCE : -ACTIVATION_DISTANCE;
+
   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))
+      && ((player_bbox.p2.x + x_offset) > owl_bbox.p1.x)
+      && ((player_bbox.p1.x + x_offset) < owl_bbox.p2.x))
     return true;
   else
     return false;
@@ -138,21 +144,5 @@ Owl::collision_solid(const CollisionHit& hit)
   }
 } /* void Owl::collision_solid */
 
-HitResponse
-Owl::collision_player(Player& player, const CollisionHit& hit)
-{
-  //Hack to tell if we should die
-  HitResponse response = BadGuy::collision_player(player, hit);
-  if(response == FORCE_MOVE) {
-    if (carried_object != NULL) {
-      carried_object->ungrab (*this, dir);
-      carried_object = NULL;
-    }
-    kill_fall ();
-  }
-
-  return ABORT_MOVE;
-}
-
 /* vim: set sw=2 sts=2 et fdm=marker : */
 /* EOF */
index 64a7640..ae441b0 100644 (file)
@@ -34,7 +34,6 @@ 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);
 
   std::string carried_obj_name;
   Portable *carried_object;