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 "badguy/snowball.hpp"
20 #include "object/player.hpp"
21 #include "supertux/sector.hpp"
23 Snowman::Snowman(const Reader& reader) :
24 WalkingBadguy(reader, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right")
29 Snowman::Snowman(const Vector& pos, Direction d) :
30 WalkingBadguy(pos, d, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right")
36 Snowman::collision_squished(GameObject& object)
38 // replace with Snowball
39 Vector snowball_pos = get_pos();
40 // Hard-coded values from sprites
45 Player* player = dynamic_cast<Player*>(&object);
47 player->bounce(*this);
49 /* Create death animation for the (now headless) snowman. */
50 set_action (dir == LEFT ? "headless-left" : "headless-right", /* loops = */ -1);
51 set_pos (get_pos () + Vector (-4.0, 19.0)); /* difference in the sprite offsets */
52 physic.set_velocity_y(0);
53 physic.set_acceleration_y(0);
54 physic.enable_gravity(true);
55 set_state (STATE_FALLING);
57 /* Create a new snowball where the snowman's head was */
58 /* TODO: Pass on our "dead_script" to the snowball. */
59 SnowBall* snowball = new SnowBall(snowball_pos, dir);
60 Sector::current()->add_object(snowball);