X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Fsnowman.cpp;h=6170ae1f97d81102021e9a57b02a8fa0cab01809;hb=701460d787f5c617e6a03955cf6d736020a0003f;hp=e353113282c750a4b1c5710969c0649ccb440c19;hpb=830aabe0656083bcd0353e2da2220fa709fb8e3b;p=supertux.git diff --git a/src/badguy/snowman.cpp b/src/badguy/snowman.cpp index e35311328..6170ae1f9 100644 --- a/src/badguy/snowman.cpp +++ b/src/badguy/snowman.cpp @@ -1,5 +1,5 @@ // SuperTux -// Copyright (C) 2010 Ingo Ruhnke +// Copyright (C) 2010 Ingo Ruhnke // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -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" @@ -24,16 +26,11 @@ Snowman::Snowman(const Reader& reader) : WalkingBadguy(reader, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right") { walk_speed = 40; + SoundManager::current()->preload("sounds/pop.ogg"); } -Snowman::Snowman(const Vector& pos, Direction d) : - WalkingBadguy(pos, d, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right") -{ - walk_speed = 40; -} - -bool -Snowman::collision_squished(GameObject& object) +void +Snowman::loose_head() { // replace with Snowball Vector snowball_pos = get_pos(); @@ -41,17 +38,51 @@ Snowman::collision_squished(GameObject& object) snowball_pos.x += 5; snowball_pos.y += 1; - SnowBall* snowball = new SnowBall(snowball_pos, dir); - remove_me(); + /* 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 */ + physic.set_velocity_y(0); + physic.set_acceleration_y(0); + physic.enable_gravity(true); + set_state (STATE_FALLING); + countMe = false; + + /* Create a new snowball where the snowman's head was */ + auto snowball = std::make_shared(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(); + SoundManager::current()->play("sounds/pop.ogg", get_pos()); // this could be a different sound + 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); -/* - sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); - kill_squished(object); -*/ + if (player) + player->bounce(*this); + + SoundManager::current()->play("sounds/pop.ogg", get_pos()); + + loose_head(); + return true; }