4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #include "random_generator.hpp"
24 #include "object/sprite_particle.hpp"
25 #include "object/explosion.hpp"
27 Bomb::Bomb(const Vector& pos, Direction dir, std::string custom_sprite /*= "images/creatures/mr_bomb/mr_bomb.sprite"*/ )
28 : BadGuy( pos, dir, custom_sprite )
30 state = STATE_TICKING;
31 set_action(dir == LEFT ? "ticking-left" : "ticking-right", 1);
34 ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav"));
35 ticking->set_position(get_pos());
36 ticking->set_looping(true);
37 ticking->set_gain(2.0);
38 ticking->set_reference_distance(32);
42 Bomb::Bomb(const Bomb& other)
43 : BadGuy(other), state(other.state)
45 if (state == STATE_TICKING) {
46 ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav"));
47 ticking->set_position(get_pos());
48 ticking->set_looping(true);
49 ticking->set_gain(2.0);
50 ticking->set_reference_distance(32);
56 Bomb::write(lisp::Writer& )
58 // bombs are only temporarily so don't write them out...
62 Bomb::collision_solid(const CollisionHit& hit)
65 physic.set_velocity_y(0);
69 Bomb::collision_player(Player& player, const CollisionHit& )
71 if(state == STATE_EXPLODING) {
78 Bomb::collision_badguy(BadGuy& badguy, const CollisionHit& )
80 if(state == STATE_EXPLODING)
86 Bomb::active_update(float )
90 ticking->set_position(get_pos());
91 if(sprite->animation_done()) {
96 if(sprite->animation_done()) {
109 Explosion* explosion = new Explosion(get_bbox().get_middle());
110 Sector::current()->add_object(explosion);
118 if (state != STATE_EXPLODING) // we don't want it exploding again