From: florianf Date: Sat, 6 Mar 2010 17:02:19 +0000 (+0000) Subject: Owl: Let go of the carried object when above Tux. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=32bc2fa949c1bd7f415beb07187b641a2c3507e5;p=supertux.git Owl: Let go of the carried object when above Tux. git-svn-id: http://supertux.lethargik.org/svn/supertux/trunk/supertux@6562 837edb03-e0f3-0310-88ca-d4d4e8b29345 --- diff --git a/src/badguy/owl.cpp b/src/badguy/owl.cpp index 6389f71da..5677ef0c3 100644 --- a/src/badguy/owl.cpp +++ b/src/badguy/owl.cpp @@ -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; } diff --git a/src/badguy/owl.hpp b/src/badguy/owl.hpp index 7510cae44..64a76403a 100644 --- a/src/badguy/owl.hpp +++ b/src/badguy/owl.hpp @@ -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);