2 // Copyright (C) 2010 Ingo Ruhnke <grumbel@gmx.de>
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")
31 Snowman::Snowman(const Vector& pos, Direction d) :
32 WalkingBadguy(pos, d, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right")
40 // replace with Snowball
41 Vector snowball_pos = get_pos();
42 // Hard-coded values from sprites
46 /* Create death animation for the (now headless) snowman. */
47 set_action (dir == LEFT ? "headless-left" : "headless-right", /* loops = */ -1);
48 set_pos (get_pos () + Vector (-4.0, 19.0)); /* difference in the sprite offsets */
49 physic.set_velocity_y(0);
50 physic.set_acceleration_y(0);
51 physic.enable_gravity(true);
52 set_state (STATE_FALLING);
54 /* Create a new snowball where the snowman's head was */
55 SnowBall* snowball = new SnowBall(snowball_pos, dir, dead_script);
56 Sector::current()->add_object(snowball);
60 Snowman::collision_bullet(Bullet& bullet, const CollisionHit& hit)
62 if(bullet.get_type() == FIRE_BONUS) {
63 // fire bullets destroy snowman's body
66 // FIXME: the sound used here should differ since there is still a threat
67 sound_manager->play("sounds/fall.wav", get_pos());
73 // in all other cases, bullets ricochet
74 bullet.ricochet(*this, hit);
80 Snowman::collision_squished(GameObject& object)
83 Player* player = dynamic_cast<Player*>(&object);
85 player->bounce(*this);
87 // FIXME: the squish sound isn't best here
88 sound_manager->play("sounds/squish.wav", get_pos());