X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fbomb.cpp;h=cbc96c0a09d2b65f227ba585f5e32fb59ab9419a;hb=7a6f00e27bdc0aac2107506c3b00cbf0bf1cccc5;hp=6f884f1093270004278c152bfea67a0af9912a0f;hpb=6fe1f3519eecbbb75eca97c45a6697eee36b2442;p=supertux.git diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index 6f884f109..cbc96c0a0 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -1,66 +1,104 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include -#include "bomb.h" +#include "bomb.hpp" +#include "random_generator.hpp" +#include "object/explosion.hpp" -static const float TICKINGTIME = 1; -static const float EXPLOSIONTIME = 1; +Bomb::Bomb(const Vector& pos, Direction dir, std::string custom_sprite /*= "images/creatures/mr_bomb/mr_bomb.sprite"*/ ) + : BadGuy( pos, dir, custom_sprite ) +{ + state = STATE_TICKING; + set_action(dir == LEFT ? "ticking-left" : "ticking-right", 1); + countMe = false; -Bomb::Bomb(const Vector& pos, Direction dir) + 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(); +} + +Bomb::Bomb(const Bomb& other) + : BadGuy(other), state(other.state) { - start_position = pos; - bbox.set_pos(pos); - bbox.set_size(32, 32); - sprite = sprite_manager->create("bomb"); - state = 0; - timer.start(TICKINGTIME); - this->dir = dir; - sprite->set_action(dir == LEFT ? "ticking-left" : "ticking-right"); + if (state == STATE_TICKING) { + 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(); + } } void -Bomb::write(LispWriter& ) +Bomb::write(lisp::Writer& ) { // bombs are only temporarily so don't write them out... } -HitResponse -Bomb::collision_solid(GameObject& , const CollisionHit& hit) +void +Bomb::collision_solid(const CollisionHit& hit) { - if(fabsf(hit.normal.y) > .5) + if(hit.bottom) physic.set_velocity_y(0); +} - return CONTINUE; +HitResponse +Bomb::collision_player(Player& , const CollisionHit& ) +{ + return ABORT_MOVE; } HitResponse -Bomb::collision_player(Player& player, const CollisionHit& ) +Bomb::collision_badguy(BadGuy& , const CollisionHit& ) { - if(state == 1) { - player.kill(Player::SHRINK); - } return ABORT_MOVE; } void -Bomb::active_action(float ) +Bomb::active_update(float ) { - switch(state) { - case 0: - if(timer.check()) { - state = 1; - sprite->set_action("explosion"); - timer.start(EXPLOSIONTIME); - } - break; - case 1: - if(timer.check()) { - remove_me(); - } - break; - } + ticking->set_position(get_pos()); + if(sprite->animation_done()) { + explode(); + } +} + +void +Bomb::explode() +{ + ticking->stop(); + + remove_me(); + Explosion* explosion = new Explosion(get_bbox().get_middle()); + Sector::current()->add_object(explosion); + + run_dead_script(); } void Bomb::kill_fall() { + explode(); }