From: LMH Date: Sun, 15 Sep 2013 22:08:15 +0000 (-1000) Subject: Snowman enhancements: dead-script is passed to snowball, fireballs only kill body... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=42e5d5c0678e169b9e57b282c18f11caf8f29554;p=supertux.git Snowman enhancements: dead-script is passed to snowball, fireballs only kill body, and jumping on produces a sound. TODO: the sounds used here should be changed, consider them placeholders. --- diff --git a/src/badguy/snowball.cpp b/src/badguy/snowball.cpp index 7629a4fc8..3e286ccee 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 ab881c6b0..6f8f64f37 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 4a3cc2cd5..5cbd5c7b0 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 fd9438a0b..a07307332 100644 --- a/src/badguy/snowman.hpp +++ b/src/badguy/snowman.hpp @@ -29,7 +29,10 @@ public: 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