00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "audio/sound_manager.hpp"
00018 #include "badguy/bomb.hpp"
00019 #include "object/explosion.hpp"
00020 #include "object/player.hpp"
00021 #include "sprite/sprite.hpp"
00022 #include "supertux/sector.hpp"
00023
00024 Bomb::Bomb(const Vector& pos, Direction dir, std::string custom_sprite ) :
00025 BadGuy( pos, dir, custom_sprite ),
00026 state(),
00027 grabbed(false),
00028 grabber(NULL),
00029 ticking()
00030 {
00031 state = STATE_TICKING;
00032 set_action(dir == LEFT ? "ticking-left" : "ticking-right", 1);
00033 countMe = false;
00034
00035 ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav"));
00036 ticking->set_position(get_pos());
00037 ticking->set_looping(true);
00038 ticking->set_gain(2.0);
00039 ticking->set_reference_distance(32);
00040 ticking->play();
00041 }
00042
00043 void
00044 Bomb::collision_solid(const CollisionHit& hit)
00045 {
00046 if(hit.bottom)
00047 physic.set_velocity_y(0);
00048
00049 update_on_ground_flag(hit);
00050 }
00051
00052 HitResponse
00053 Bomb::collision_player(Player& , const CollisionHit& )
00054 {
00055 return ABORT_MOVE;
00056 }
00057
00058 HitResponse
00059 Bomb::collision_badguy(BadGuy& , const CollisionHit& )
00060 {
00061 return ABORT_MOVE;
00062 }
00063
00064 void
00065 Bomb::active_update(float elapsed_time)
00066 {
00067 ticking->set_position(get_pos());
00068 if(sprite->animation_done()) {
00069 explode();
00070 }
00071 else if (!grabbed) {
00072 movement = physic.get_movement(elapsed_time);
00073 }
00074 }
00075
00076 void
00077 Bomb::explode()
00078 {
00079 ticking->stop();
00080
00081
00082
00083
00084 if (grabber != NULL) {
00085 Player* player = dynamic_cast<Player*>(grabber);
00086
00087 if (player)
00088 player->stop_grabbing();
00089 }
00090
00091 if(is_valid()) {
00092 remove_me();
00093 Explosion* explosion = new Explosion(get_bbox().get_middle());
00094 Sector::current()->add_object(explosion);
00095 }
00096
00097 run_dead_script();
00098 }
00099
00100 void
00101 Bomb::kill_fall()
00102 {
00103 explode();
00104 }
00105
00106 void
00107 Bomb::grab(MovingObject& object, const Vector& pos, Direction dir)
00108 {
00109 movement = pos - get_pos();
00110 this->dir = dir;
00111
00112
00113
00114 sprite->set_action_continued(dir == LEFT ? "ticking-right" : "ticking-left");
00115 set_colgroup_active(COLGROUP_DISABLED);
00116 grabbed = true;
00117 grabber = &object;
00118 }
00119
00120 void
00121 Bomb::ungrab(MovingObject& object, Direction dir)
00122 {
00123 this->dir = dir;
00124
00125
00126 set_pos(object.get_pos() + Vector(dir == LEFT ? -16 : 16, get_bbox().get_height()*0.66666 - 32));
00127 set_colgroup_active(COLGROUP_MOVING);
00128 grabbed = false;
00129 }
00130
00131