From: florianf Date: Sat, 6 Mar 2010 17:16:38 +0000 (+0000) Subject: Owl: Add an offset to the "is_above_player()" method. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6ead23f303b772ace327abc7cbfc9b33b6d8c9ad;p=supertux.git Owl: Add an offset to the "is_above_player()" method. 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 --- diff --git a/src/badguy/owl.cpp b/src/badguy/owl.cpp index 5677ef0c3..a110b23c6 100644 --- a/src/badguy/owl.cpp +++ b/src/badguy/owl.cpp @@ -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 */ diff --git a/src/badguy/owl.hpp b/src/badguy/owl.hpp index 64a76403a..ae441b092 100644 --- a/src/badguy/owl.hpp +++ b/src/badguy/owl.hpp @@ -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;