Snowman: Created body-only animation and added it to the squished collision handler.
[supertux.git] / src / badguy / snowman.cpp
1 //  SuperTux
2 //  Copyright (C) 2010 Ingo Ruhnke <grumbel@gmx.de>
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 "badguy/snowball.hpp"
20 #include "object/player.hpp"
21 #include "supertux/sector.hpp"
22
23 Snowman::Snowman(const Reader& reader) :
24   WalkingBadguy(reader, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right")
25 {
26   walk_speed = 40;
27 }
28
29 Snowman::Snowman(const Vector& pos, Direction d) :
30   WalkingBadguy(pos, d, "images/creatures/snowman/snowman.sprite", "walk-left", "walk-right")
31 {
32   walk_speed = 40;
33 }
34
35 bool
36 Snowman::collision_squished(GameObject& object)
37 {
38   // replace with Snowball
39   Vector snowball_pos = get_pos();
40   // Hard-coded values from sprites
41   snowball_pos.x += 5;
42   snowball_pos.y += 1;
43
44   // bounce
45   Player* player = dynamic_cast<Player*>(&object);
46   if (player)
47     player->bounce(*this);
48
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);
56
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);
61
62   return true;
63 }
64
65 /* EOF */