From: Wolfgang Becker Date: Fri, 11 Apr 2008 20:26:54 +0000 (+0000) Subject: Dispenser no longer hurts Tux directly. Tux can climb on it. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7366b5d01e95ddb57f63a8800b8c734e404df748;p=supertux.git Dispenser no longer hurts Tux directly. Tux can climb on it. SVN-Revision: 5388 --- diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index 73a931b6a..2a9d03e9e 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -20,6 +20,7 @@ #include #include "dispenser.hpp" +#include "object/bullet.hpp" #include "badguy/bouncing_snowball.hpp" #include "badguy/snowball.hpp" #include "badguy/mrbomb.hpp" @@ -35,12 +36,16 @@ Dispenser::Dispenser(const lisp::Lisp& reader) : BadGuy(reader, "images/creatures/dispenser/dispenser.sprite") { + set_colgroup_active(COLGROUP_MOVING_STATIC); + sound_manager->preload("sounds/squish.wav"); reader.get("cycle", cycle); reader.get("badguy", badguy); autotarget = false; swivel = false; + broken = false; if (badguy == "mrrocket") { sprite->set_action(dir == LEFT ? "working-left" : "working-right"); + set_colgroup_active(COLGROUP_MOVING); //if this were COLGROUP_MOVING_STATIC MrRocket would explode on launch. if( start_dir == AUTO ){ autotarget = true; } @@ -69,7 +74,10 @@ Dispenser::write(lisp::Writer& writer) void Dispenser::activate() { - if( autotarget && !swivel ){ // auto canon sprite might be wrong + if( broken ){ + return; + } + if( autotarget && !swivel ){ // auto cannon sprite might be wrong Player* player = this->get_nearest_player(); if( player ){ dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT; @@ -90,15 +98,48 @@ Dispenser::deactivate() bool Dispenser::collision_squished(GameObject& object) { - //TODO: Should it act like a normal tile when killed? + //Cannon launching MrRocket can be broken by jumping on it + //other dispencers are not that fragile. + if (broken || badguy != "mrrocket") { + return false; + } sprite->set_action(dir == LEFT ? "broken-left" : "broken-right"); dispense_timer.start(0); + set_colgroup_active(COLGROUP_MOVING_STATIC); // Tux can stand on broken cannon. Player* player = dynamic_cast(&object); - if (player) player->bounce(*this); - kill_squished(object); + if (player){ + player->bounce(*this); + } + sound_manager->play("sounds/squish.wav", get_pos()); + broken = true; return true; } +HitResponse +Dispenser::collision(GameObject& other, const CollisionHit& hit) +{ + Player* player = dynamic_cast (&other); + if(player) { + // hit from above? + if (player->get_bbox().p2.y < (bbox.p1.y + 16)) { + collision_squished(*player); + return FORCE_MOVE; + } + if(frozen){ + unfreeze(); + } + return FORCE_MOVE; + } + + Bullet* bullet = dynamic_cast (&other); + if(bullet){ + return collision_bullet(*bullet, hit); + } + + return FORCE_MOVE; +} + + void Dispenser::active_update(float ) { diff --git a/src/badguy/dispenser.hpp b/src/badguy/dispenser.hpp index 95b5cad2b..38a26fe31 100644 --- a/src/badguy/dispenser.hpp +++ b/src/badguy/dispenser.hpp @@ -41,12 +41,14 @@ public: protected: bool collision_squished(GameObject& object); + HitResponse collision(GameObject& other, const CollisionHit& hit); void launch_badguy(); float cycle; std::string badguy; Timer dispense_timer; bool autotarget; bool swivel; + bool broken; }; #endif