2 // Copyright (C) 2010 Ingo Ruhnke <grumbel@gmail.com>
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.
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.
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/>.
17 #include "badguy/snowman.hpp"
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"
25 Snowman::Snowman(const Reader& reader) :
26 WalkingBadguy(reader, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right")
29 SoundManager::current()->preload("sounds/pop.ogg");
35 // replace with Snowball
36 Vector snowball_pos = get_pos();
37 // Hard-coded values from sprites
41 /* Create death animation for the (now headless) snowman. */
42 set_action (dir == LEFT ? "headless-left" : "headless-right", /* loops = */ -1);
43 set_pos (get_pos () + Vector (-4.0, 19.0)); /* difference in the sprite offsets */
44 physic.set_velocity_y(0);
45 physic.set_acceleration_y(0);
46 physic.enable_gravity(true);
47 set_state (STATE_FALLING);
49 /* Create a new snowball where the snowman's head was */
50 SnowBall* snowball = new SnowBall(snowball_pos, dir, dead_script);
51 Sector::current()->add_object(snowball);
55 Snowman::collision_bullet(Bullet& bullet, const CollisionHit& hit)
57 if(bullet.get_type() == FIRE_BONUS) {
58 // fire bullets destroy snowman's body
61 SoundManager::current()->play("sounds/pop.ogg", get_pos()); // this could be a different sound
67 // in all other cases, bullets ricochet
68 bullet.ricochet(*this, hit);
74 Snowman::collision_squished(GameObject& object)
77 Player* player = dynamic_cast<Player*>(&object);
79 player->bounce(*this);
81 SoundManager::current()->play("sounds/pop.ogg", get_pos());