| 1 | // SuperTux |
| 2 | // Copyright (C) 2010 Ingo Ruhnke <grumbel@gmail.com> |
| 3 | // |
| 4 | // This program is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | |
| 17 | #include "badguy/snowman.hpp" |
| 18 | |
| 19 | #include "audio/sound_manager.hpp" |
| 20 | #include "badguy/snowball.hpp" |
| 21 | #include "object/bullet.hpp" |
| 22 | #include "object/player.hpp" |
| 23 | #include "supertux/sector.hpp" |
| 24 | |
| 25 | Snowman::Snowman(const ReaderMapping& reader) : |
| 26 | WalkingBadguy(reader, "images/creatures/snowman/snowman.sprite" , "left" , "right" ) |
| 27 | { |
| 28 | walk_speed = 40; |
| 29 | SoundManager::current()->preload("sounds/pop.ogg" ); |
| 30 | } |
| 31 | |
| 32 | void |
| 33 | Snowman::loose_head() |
| 34 | { |
| 35 | // replace with Snowball |
| 36 | Vector snowball_pos = get_pos(); |
| 37 | // Hard-coded values from sprites |
| 38 | snowball_pos.x += 5; |
| 39 | snowball_pos.y += 1; |
| 40 | |
| 41 | /* Create death animation for the (now headless) snowman. */ |
| 42 | set_action (m_dir == Direction::LEFT ? "headless-left" : "headless-right" , /* loops = */ -1); |
| 43 | set_pos (get_pos () + Vector (-4.0, 19.0)); /* difference in the sprite offsets */ |
| 44 | m_physic.set_velocity_y(0); |
| 45 | m_physic.set_acceleration_y(0); |
| 46 | m_physic.enable_gravity(true); |
| 47 | set_state (STATE_FALLING); |
| 48 | m_countMe = false; |
| 49 | |
| 50 | /* Create a new snowball where the snowman's head was */ |
| 51 | Sector::get().add<SnowBall>(snowball_pos, m_dir, m_dead_script); |
| 52 | } |
| 53 | |
| 54 | HitResponse |
| 55 | Snowman::collision_bullet(Bullet& bullet, const CollisionHit& hit) |
| 56 | { |
| 57 | if (bullet.get_type() == FIRE_BONUS) { |
| 58 | // fire bullets destroy snowman's body |
| 59 | Vector snowball_pos = get_pos(); |
| 60 | // Hard-coded values from sprites |
| 61 | snowball_pos.x += 5; |
| 62 | snowball_pos.y += 1; |
| 63 | |
| 64 | /* Create a new snowball where the snowman's head was */ |
| 65 | Sector::get().add<SnowBall>(snowball_pos, m_dir, m_dead_script); |
| 66 | |
| 67 | SoundManager::current()->play("sounds/pop.ogg" , get_pos()); // this could be a different sound |
| 68 | bullet.remove_me(); |
| 69 | ignite(); |
| 70 | |
| 71 | return ABORT_MOVE; |
| 72 | } |
| 73 | else { |
| 74 | // in all other cases, bullets ricochet |
| 75 | bullet.ricochet(*this, hit); |
| 76 | return FORCE_MOVE; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | bool |
| 81 | Snowman::collision_squished(GameObject& object) |
| 82 | { |
| 83 | auto player = dynamic_cast<Player*>(&object); |
| 84 | if (player && (player->m_does_buttjump || player->is_invincible())) { |
| 85 | player->bounce(*this); |
| 86 | kill_fall(); |
| 87 | return true; |
| 88 | } |
| 89 | |
| 90 | // bounce |
| 91 | if (player) |
| 92 | player->bounce(*this); |
| 93 | |
| 94 | SoundManager::current()->play("sounds/pop.ogg" , get_pos()); |
| 95 | |
| 96 | loose_head(); |
| 97 | |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | /* EOF */ |
| 102 | |