X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fbadguy%2Fbomb.cpp;h=c9e2c8a611fa1e4ed78afa679d9703de36f49272;hb=a3316d68ca17966517c3f7bb0c0cb2b7e612fd0a;hp=4b70b213501215ffa390cce76e9be241b8b2c809;hpb=4f1aaead7061c8cee1704f887fc7e1a2bc7b387c;p=supertux.git diff --git a/src/badguy/bomb.cpp b/src/badguy/bomb.cpp index 4b70b2135..c9e2c8a61 100644 --- a/src/badguy/bomb.cpp +++ b/src/badguy/bomb.cpp @@ -23,16 +23,11 @@ #include "random_generator.hpp" #include "object/sprite_particle.hpp" -static const float TICKINGTIME = 1; -static const float EXPLOSIONTIME = 1; - -Bomb::Bomb(const Vector& pos, Direction dir) - : BadGuy(pos, "images/creatures/mr_cherry/cherry.sprite") +Bomb::Bomb(const Vector& pos, Direction dir, std::string custom_sprite /*= "images/creatures/mr_cherry/cherry.sprite"*/ ) + : BadGuy( pos, dir, custom_sprite ) { state = STATE_TICKING; - timer.start(TICKINGTIME); - this->dir = dir; - sprite->set_action(dir == LEFT ? "ticking-left" : "ticking-right"); + set_action(dir == LEFT ? "ticking-left" : "ticking-right", 1); countMe = false; ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav")); @@ -44,7 +39,7 @@ Bomb::Bomb(const Vector& pos, Direction dir) } Bomb::Bomb(const Bomb& other) - : BadGuy(other), state(other.state), timer(other.timer) + : BadGuy(other), state(other.state) { if (state == STATE_TICKING) { ticking.reset(sound_manager->create_sound_source("sounds/fizz.wav")); @@ -62,13 +57,11 @@ 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 @@ -94,12 +87,12 @@ Bomb::active_update(float ) switch(state) { case STATE_TICKING: ticking->set_position(get_pos()); - if(timer.check()) { + if(sprite->animation_done()) { explode(); } break; case STATE_EXPLODING: - if(timer.check()) { + if(sprite->animation_done()) { remove_me(); } break; @@ -112,22 +105,21 @@ Bomb::explode() ticking->stop(); state = STATE_EXPLODING; set_group(COLGROUP_TOUCHABLE); - sprite->set_action("explosion"); sound_manager->play("sounds/explosion.wav", get_pos()); - timer.start(EXPLOSIONTIME); - -// spawn some particles - // TODO: provide convenience function in MovingSprite or MovingObject? - for (int i = 0; i < 100; i++) { - Vector ppos = bbox.get_middle(); - float angle = systemRandom.randf(-M_PI_2, M_PI_2); - float velocity = systemRandom.randf(450, 900); - float vx = sin(angle)*velocity; - float vy = -cos(angle)*velocity; - Vector pspeed = Vector(vx, vy); - Vector paccel = Vector(0, 1000); - Sector::current()->add_object(new SpriteParticle("images/objects/particles/kracker.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1)); - } + set_action_centered("explosion", 1); + + // spawn some particles + // TODO: provide convenience function in MovingSprite or MovingObject? + for (int i = 0; i < 100; i++) { + Vector ppos = bbox.get_middle(); + float angle = systemRandom.randf(-M_PI_2, M_PI_2); + float velocity = systemRandom.randf(450, 900); + float vx = sin(angle)*velocity; + float vy = -cos(angle)*velocity; + Vector pspeed = Vector(vx, vy); + Vector paccel = Vector(0, 1000); + Sector::current()->add_object(new SpriteParticle("images/objects/particles/kracker.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1)); + } }