X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fbomb.cpp;h=55e630f1c6e4de635ecd80af9da3aceacfa57c54;hb=2ad3ecbc14b77d373c796ad04d6389489666cc01;hp=cbc96c0a09d2b65f227ba585f5e32fb59ab9419a;hpb=b190b1597483fe76b98b6fcda1ba8f2d037dd8ed;p=supertux.git diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index cbc96c0a0..55e630f1c 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -22,9 +22,14 @@ #include "bomb.hpp" #include "random_generator.hpp" #include "object/explosion.hpp" +#include "audio/sound_manager.hpp" +#include "lisp/writer.hpp" +#include "sprite/sprite.hpp" +#include "object/player.hpp" +#include "sector.hpp" Bomb::Bomb(const Vector& pos, Direction dir, std::string custom_sprite /*= "images/creatures/mr_bomb/mr_bomb.sprite"*/ ) - : BadGuy( pos, dir, custom_sprite ) + : BadGuy( pos, dir, custom_sprite ), grabbed(false), grabber(NULL) { state = STATE_TICKING; set_action(dir == LEFT ? "ticking-left" : "ticking-right", 1); @@ -39,7 +44,7 @@ Bomb::Bomb(const Vector& pos, Direction dir, std::string custom_sprite /*= "imag } Bomb::Bomb(const Bomb& other) - : BadGuy(other), state(other.state) + : BadGuy(other), Portable(other), state(other.state) { if (state == STATE_TICKING) { ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav")); @@ -62,6 +67,8 @@ Bomb::collision_solid(const CollisionHit& hit) { if(hit.bottom) physic.set_velocity_y(0); + + update_on_ground_flag(hit); } HitResponse @@ -77,12 +84,15 @@ Bomb::collision_badguy(BadGuy& , const CollisionHit& ) } void -Bomb::active_update(float ) +Bomb::active_update(float elapsed_time) { ticking->set_position(get_pos()); if(sprite->animation_done()) { explode(); } + else if (!grabbed) { + movement = physic.get_movement(elapsed_time); + } } void @@ -90,9 +100,21 @@ Bomb::explode() { ticking->stop(); - remove_me(); - Explosion* explosion = new Explosion(get_bbox().get_middle()); - Sector::current()->add_object(explosion); + // Make the player let go before we explode, otherwise the player is holding + // an invalid object. There's probably a better way to do this than in the + // Bomb class. + if (grabber != NULL) { + Player* player = dynamic_cast(grabber); + + if (player) + player->stop_grabbing(); + } + + if(is_valid()) { + remove_me(); + Explosion* explosion = new Explosion(get_bbox().get_middle()); + Sector::current()->add_object(explosion); + } run_dead_script(); } @@ -102,3 +124,29 @@ Bomb::kill_fall() { explode(); } + +void +Bomb::grab(MovingObject& object, const Vector& pos, Direction dir) +{ + movement = pos - get_pos(); + this->dir = dir; + + // We actually face the opposite direction of Tux here to make the fuse more + // visible instead of hiding it behind Tux + sprite->set_action_continued(dir == LEFT ? "ticking-right" : "ticking-left"); + set_colgroup_active(COLGROUP_DISABLED); + grabbed = true; + grabber = &object; +} + +void +Bomb::ungrab(MovingObject& object, Direction dir) +{ + this->dir = dir; + // portable objects are usually pushed away from Tux when dropped, but we + // don't want that, so we set the position + set_pos(object.get_pos() + Vector(dir == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32)); + set_colgroup_active(COLGROUP_MOVING); + grabbed = false; +} +