diff --git a/src/badguy/snowball.cpp b/src/badguy/snowball.cpp index 7629a4fc8fe..3e286cceeac 100644 --- a/src/badguy/snowball.cpp +++ b/src/badguy/snowball.cpp @@ -25,10 +25,11 @@ SnowBall::SnowBall(const Reader& reader) walk_speed = 80; } -SnowBall::SnowBall(const Vector& pos, Direction d) +SnowBall::SnowBall(const Vector& pos, Direction d, std::string script) : WalkingBadguy(pos, d, "images/creatures/snowball/snowball.sprite", "left", "right") { walk_speed = 80; + dead_script = script; } bool diff --git a/src/badguy/snowball.hpp b/src/badguy/snowball.hpp index ab881c6b06e..6f8f64f37de 100644 --- a/src/badguy/snowball.hpp +++ b/src/badguy/snowball.hpp @@ -23,7 +23,7 @@ class SnowBall : public WalkingBadguy { public: SnowBall(const Reader& reader); - SnowBall(const Vector& pos, Direction d); + SnowBall(const Vector& pos, Direction d, std::string script); protected: bool collision_squished(GameObject& object); diff --git a/src/badguy/snowman.cpp b/src/badguy/snowman.cpp index 4a3cc2cd525..5cbd5c7b0ec 100644 --- a/src/badguy/snowman.cpp +++ b/src/badguy/snowman.cpp @@ -16,7 +16,9 @@ #include "badguy/snowman.hpp" +#include "audio/sound_manager.hpp" #include "badguy/snowball.hpp" +#include "object/bullet.hpp" #include "object/player.hpp" #include "supertux/sector.hpp" @@ -32,8 +34,8 @@ Snowman::Snowman(const Vector& pos, Direction d) : walk_speed = 40; } -bool -Snowman::collision_squished(GameObject& object) +void +Snowman::loose_head() { // replace with Snowball Vector snowball_pos = get_pos(); @@ -41,11 +43,6 @@ Snowman::collision_squished(GameObject& object) snowball_pos.x += 5; snowball_pos.y += 1; - // bounce - Player* player = dynamic_cast(&object); - if (player) - player->bounce(*this); - /* Create death animation for the (now headless) snowman. */ set_action (dir == LEFT ? "headless-left" : "headless-right", /* loops = */ -1); set_pos (get_pos () + Vector (-4.0, 19.0)); /* difference in the sprite offsets */ @@ -55,9 +52,42 @@ Snowman::collision_squished(GameObject& object) set_state (STATE_FALLING); /* Create a new snowball where the snowman's head was */ - /* TODO: Pass on our "dead_script" to the snowball. */ - SnowBall* snowball = new SnowBall(snowball_pos, dir); + SnowBall* snowball = new SnowBall(snowball_pos, dir, dead_script); Sector::current()->add_object(snowball); +} + +HitResponse +Snowman::collision_bullet(Bullet& bullet, const CollisionHit& hit) +{ + if(bullet.get_type() == FIRE_BONUS) { + // fire bullets destroy snowman's body + loose_head(); + + // FIXME: the sound used here should differ since there is still a threat + sound_manager->play("sounds/fall.wav", get_pos()); + bullet.remove_me(); + + return ABORT_MOVE; + } + else { + // in all other cases, bullets ricochet + bullet.ricochet(*this, hit); + return FORCE_MOVE; + } +} + +bool +Snowman::collision_squished(GameObject& object) +{ + // bounce + Player* player = dynamic_cast(&object); + if (player) + player->bounce(*this); + + // FIXME: the squish sound isn't best here + sound_manager->play("sounds/squish.wav", get_pos()); + + loose_head(); return true; } diff --git a/src/badguy/snowman.hpp b/src/badguy/snowman.hpp index fd9438a0bf8..a07307332ef 100644 --- a/src/badguy/snowman.hpp +++ b/src/badguy/snowman.hpp @@ -29,7 +29,10 @@ class Snowman : public WalkingBadguy Snowman(const Vector& pos, Direction d); protected: + void loose_head(); + virtual HitResponse collision_bullet(Bullet& bullet, const CollisionHit& hit); bool collision_squished(GameObject& object); + }; #endif