2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "audio/sound_manager.hpp"
18 #include "badguy/bomb.hpp"
19 #include "object/explosion.hpp"
20 #include "object/player.hpp"
21 #include "sprite/sprite.hpp"
22 #include "supertux/sector.hpp"
24 Bomb::Bomb(const Vector& pos, Direction dir_, std::string custom_sprite /*= "images/creatures/mr_bomb/mr_bomb.sprite"*/ ) :
25 BadGuy( pos, dir_, custom_sprite ),
31 state = STATE_TICKING;
32 set_action(dir_ == LEFT ? "ticking-left" : "ticking-right", 1);
35 ticking = SoundManager::current()->create_sound_source("sounds/fizz.wav");
36 ticking->set_position(get_pos());
37 ticking->set_looping(true);
38 ticking->set_gain(2.0);
39 ticking->set_reference_distance(32);
44 Bomb::collision_solid(const CollisionHit& hit)
47 physic.set_velocity_y(0);
49 update_on_ground_flag(hit);
53 Bomb::collision_player(Player& , const CollisionHit& )
59 Bomb::collision_badguy(BadGuy& , const CollisionHit& )
65 Bomb::active_update(float elapsed_time)
67 ticking->set_position(get_pos());
68 if(sprite->animation_done()) {
72 movement = physic.get_movement(elapsed_time);
81 // Make the player let go before we explode, otherwise the player is holding
82 // an invalid object. There's probably a better way to do this than in the
84 if (grabber != NULL) {
85 Player* player = dynamic_cast<Player*>(grabber);
88 player->stop_grabbing();
93 auto explosion = std::make_shared<Explosion>(get_bbox().get_middle());
94 Sector::current()->add_object(explosion);
107 Bomb::grab(MovingObject& object, const Vector& pos, Direction dir_)
109 movement = pos - get_pos();
112 // We actually face the opposite direction of Tux here to make the fuse more
113 // visible instead of hiding it behind Tux
114 sprite->set_action_continued(dir == LEFT ? "ticking-right" : "ticking-left");
115 set_colgroup_active(COLGROUP_DISABLED);
121 Bomb::ungrab(MovingObject& object, Direction dir_)
124 // portable objects are usually pushed away from Tux when dropped, but we
125 // don't want that, so we set the position
126 //FIXME: why don't we want that? shouldn't behavior be consistent?
127 set_pos(object.get_pos() + Vector(dir_ == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32));
128 set_colgroup_active(COLGROUP_MOVING);