From eb7402695607f2e31299f736b8dfbc984b0c6403 Mon Sep 17 00:00:00 2001 From: Wolfgang Becker Date: Wed, 9 Aug 2006 22:55:40 +0000 Subject: [PATCH] Getting a rock on the head hurts. SVN-Revision: 4144 --- src/object/rock.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) 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; } -- 2.11.0