From: Christoph Sommer Date: Tue, 13 May 2008 21:15:29 +0000 (+0000) Subject: MrBomb keeps walking while ticking X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=885abe21ca32b9b3d620593a3153e5befe67ce8c;p=supertux.git MrBomb keeps walking while ticking SVN-Revision: 5465 --- diff --git a/data/images/creatures/mr_bomb/mr_bomb.sprite b/data/images/creatures/mr_bomb/mr_bomb.sprite index 788833572..56e221bb7 100644 --- a/data/images/creatures/mr_bomb/mr_bomb.sprite +++ b/data/images/creatures/mr_bomb/mr_bomb.sprite @@ -26,15 +26,17 @@ (action (name "ticking-left") - (fps 2.0) - (hitbox 3 8 31.8 31.8) - (images "exploding-left-0.png" - "exploding-left-1.png")) + (fps 10.0) + (hitbox 3 12 31.8 31.8) + (images "ticking-0.png" + "ticking-1.png" + "ticking-2.png" + "ticking-3.png")) (action (name "ticking-right") - (fps 2.0) - (hitbox 10 8 31.8 31.8) + (fps 10.0) + (hitbox 7 12 31.8 31.8) (mirror-action "ticking-left")) ) diff --git a/data/images/creatures/mr_bomb/ticking-0.png b/data/images/creatures/mr_bomb/ticking-0.png new file mode 100644 index 000000000..abc7872d7 Binary files /dev/null and b/data/images/creatures/mr_bomb/ticking-0.png differ diff --git a/data/images/creatures/mr_bomb/ticking-1.png b/data/images/creatures/mr_bomb/ticking-1.png new file mode 100644 index 000000000..95b7c9327 Binary files /dev/null and b/data/images/creatures/mr_bomb/ticking-1.png differ diff --git a/data/images/creatures/mr_bomb/ticking-2.png b/data/images/creatures/mr_bomb/ticking-2.png new file mode 100644 index 000000000..971129d56 Binary files /dev/null and b/data/images/creatures/mr_bomb/ticking-2.png differ diff --git a/data/images/creatures/mr_bomb/ticking-3.png b/data/images/creatures/mr_bomb/ticking-3.png new file mode 100644 index 000000000..536511200 Binary files /dev/null and b/data/images/creatures/mr_bomb/ticking-3.png differ diff --git a/src/badguy/mrbomb.cpp b/src/badguy/mrbomb.cpp index cc74c01a4..558b27097 100644 --- a/src/badguy/mrbomb.cpp +++ b/src/badguy/mrbomb.cpp @@ -20,10 +20,14 @@ #include #include "mrbomb.hpp" -#include "bomb.hpp" #include "object/explosion.hpp" #include "sprite/sprite_manager.hpp" #include "audio/sound_manager.hpp" +#include "level.hpp" + +namespace { + const float TICKING_TIME = 1.0f; /**< delay until ticking MrBomb explodes */ +} MrBomb::MrBomb(const lisp::Lisp& reader) : WalkingBadguy(reader, "images/creatures/mr_bomb/mr_bomb.sprite", "left", "right") @@ -32,9 +36,16 @@ MrBomb::MrBomb(const lisp::Lisp& reader) max_drop_height = 16; grabbed = false; - //Prevent stutter when Tux jumps on Mr Bomb sound_manager->preload("sounds/explosion.wav"); + ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav")); + ticking->set_position(get_pos()); + ticking->set_looping(true); + ticking->set_gain(2.0); + ticking->set_reference_distance(32); + + state = STATE_IDLE; + //Check if we need another sprite if( !reader.get( "sprite", sprite_name ) ){ return; @@ -55,6 +66,14 @@ MrBomb::MrBomb(const Vector& pos, Direction d) max_drop_height = 16; grabbed = false; sound_manager->preload("sounds/explosion.wav"); + + state = STATE_IDLE; + + ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav")); + ticking->set_position(get_pos()); + ticking->set_looping(true); + ticking->set_gain(2.0); + ticking->set_reference_distance(32); } void @@ -84,21 +103,58 @@ MrBomb::collision_player(Player& player, const CollisionHit& hit) bool MrBomb::collision_squished(GameObject& object) { - remove_me(); - Sector::current()->add_object(new Bomb(get_pos(), dir, sprite_name )); - kill_squished(object); + if(frozen) unfreeze(); + Player* player = dynamic_cast(&object); + if (player) { + player->bounce(*this); + } + if (state == STATE_IDLE) { + if (player && countMe) Sector::current()->get_level()->stats.badguys++; + state = STATE_TICKING; + + // TODO: currently we need to re-create ticking sound object every time, in case we had to stop it + ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav")); + ticking->set_position(get_pos()); + ticking->set_looping(true); + ticking->set_gain(2.0); + ticking->set_reference_distance(32); + + ticking->play(); + ticking_timer.start(TICKING_TIME); + walk_left_action = "ticking-left"; + walk_right_action = "ticking-right"; + sprite->set_action(dir == LEFT ? walk_left_action : walk_right_action); + } return true; } void MrBomb::active_update(float elapsed_time) { + if (state == STATE_TICKING) { + ticking->set_position(get_pos()); + if(ticking_timer.check()) { + explode(); + } + } if(grabbed) return; WalkingBadguy::active_update(elapsed_time); } void +MrBomb::explode() +{ + ticking->stop(); + + remove_me(); + Explosion* explosion = new Explosion(get_bbox().get_middle()); + Sector::current()->add_object(explosion); + + run_dead_script(); +} + +void MrBomb::kill_fall() { remove_me(); @@ -132,6 +188,19 @@ MrBomb::freeze() { WalkingBadguy::freeze(); sprite->set_action(dir == LEFT ? "iced-left" : "iced-right"); + if (state == STATE_TICKING) { + ticking_timer.stop(); + ticking->stop(); + walk_left_action = "left"; + walk_right_action = "right"; + state = STATE_IDLE; + } +} + +void +MrBomb::unfreeze() +{ + WalkingBadguy::unfreeze(); } bool diff --git a/src/badguy/mrbomb.hpp b/src/badguy/mrbomb.hpp index 14f326dec..4f28ce602 100644 --- a/src/badguy/mrbomb.hpp +++ b/src/badguy/mrbomb.hpp @@ -41,11 +41,21 @@ public: bool is_portable() const; void freeze(); + void unfreeze(); bool is_freezable() const; - virtual MrBomb* clone() const { return new MrBomb(*this); } + void explode(); protected: + enum State { + STATE_IDLE, + STATE_TICKING + }; + + State state; + std::auto_ptr ticking; + Timer ticking_timer; + bool collision_squished(GameObject& object); private: