From: Wolfgang Becker Date: Wed, 9 Aug 2006 22:55:40 +0000 (+0000) Subject: Getting a rock on the head hurts. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=eb7402695607f2e31299f736b8dfbc984b0c6403;p=supertux.git Getting a rock on the head hurts. SVN-Revision: 4144 --- diff --git a/src/object/rock.cpp b/src/object/rock.cpp index fc4fbe0a1..ab3de741c 100644 --- a/src/object/rock.cpp +++ b/src/object/rock.cpp @@ -23,6 +23,7 @@ #include "lisp/writer.hpp" #include "object_factory.hpp" #include "audio/sound_manager.hpp" +#include "tile.hpp" namespace { const std::string ROCK_SOUND = "sounds/brick.wav"; //TODO use own sound. @@ -76,24 +77,31 @@ HitResponse Rock::collision(GameObject& other, const CollisionHit& hit) { if( !on_ground ){ - return FORCE_MOVE; + if( hit.bottom && physic.get_velocity_y() > 200 ){ + MovingObject* moving_object = dynamic_cast (&other); + if( moving_object ){ + //Getting a rock on the head hurts. A lot. + moving_object->collision_tile( Tile::HURTS ); + } + } + return FORCE_MOVE; } //Fake being solid for moving_object. MovingObject* moving_object = dynamic_cast (&other); if( moving_object ){ - if( hit.top ){ - float inside = moving_object->get_bbox().get_bottom() - get_bbox().get_top(); - if( inside > 0 ){ - Vector pos = moving_object->get_pos(); - pos.y -= inside; - moving_object->set_pos( pos ); - } + if( hit.top ){ + float inside = moving_object->get_bbox().get_bottom() - get_bbox().get_top(); + if( inside > 0 ){ + Vector pos = moving_object->get_pos(); + pos.y -= inside; + moving_object->set_pos( pos ); } - CollisionHit hit_other = hit; - std::swap(hit_other.left, hit_other.right); - std::swap(hit_other.top, hit_other.bottom); - moving_object->collision_solid( hit_other ); + } + CollisionHit hit_other = hit; + std::swap(hit_other.left, hit_other.right); + std::swap(hit_other.top, hit_other.bottom); + moving_object->collision_solid( hit_other ); } return FORCE_MOVE; }