Skip to content

Commit

Permalink
Owl: Add an offset to the "is_above_player()" method.
Browse files Browse the repository at this point in the history
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".

SVN-Revision: 6563
  • Loading branch information
Florian Forster committed Mar 6, 2010
1 parent ba5abe8 commit 7e479e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
26 changes: 8 additions & 18 deletions src/badguy/owl.cpp
Expand Up @@ -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"),
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
1 change: 0 additions & 1 deletion src/badguy/owl.hpp
Expand Up @@ -34,7 +34,6 @@ class Owl : public BadGuy
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;
Expand Down

0 comments on commit 7e479e6

Please sign in to comment.