1// SuperTux
2// Copyright (C) 2008 Wolfgang Becker <uafr@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/kamikazesnowball.hpp"
18
19#include "audio/sound_manager.hpp"
20#include "sprite/sprite.hpp"
21#include "sprite/sprite_manager.hpp"
22
23namespace{
24 static const float KAMIKAZE_SPEED = 200;
25 static const float LEAFSHOT_SPEED = 400;
26 const std::string SPLAT_SOUND = "sounds/splat.wav";
27}
28
29KamikazeSnowball::KamikazeSnowball(const ReaderMapping& reader) :
30 BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite")
31{
32 SoundManager::current()->preload(SPLAT_SOUND);
33 set_action (m_dir == Direction::LEFT ? "left" : "right", /* loops = */ -1);
34}
35
36void
37KamikazeSnowball::initialize()
38{
39 m_physic.set_velocity_x(m_dir == Direction::LEFT ? -KAMIKAZE_SPEED : KAMIKAZE_SPEED);
40 m_physic.enable_gravity(false);
41 m_sprite->set_action(m_dir == Direction::LEFT ? "left" : "right");
42}
43
44bool
45KamikazeSnowball::collision_squished(GameObject& object)
46{
47 m_sprite->set_action(m_dir == Direction::LEFT ? "squished-left" : "squished-right");
48 kill_squished(object);
49 return true;
50}
51
52void
53KamikazeSnowball::collision_solid(const CollisionHit& hit)
54{
55 if (hit.top || hit.bottom) {
56 m_physic.set_velocity_y(0);
57 }
58 if (hit.left || hit.right) {
59 kill_collision();
60 }
61}
62
63void
64KamikazeSnowball::kill_collision()
65{
66 m_sprite->set_action(m_dir == Direction::LEFT ? "collision-left" : "collision-right");
67 SoundManager::current()->play(SPLAT_SOUND, get_pos());
68 m_physic.set_velocity_x(0);
69 m_physic.set_velocity_y(0);
70 m_physic.enable_gravity(true);
71 set_state(STATE_FALLING);
72
73 run_dead_script();
74}
75
76HitResponse
77KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit)
78{
79 //Hack to tell if we should die
80 HitResponse response = BadGuy::collision_player(player, hit);
81 if (response == FORCE_MOVE) {
82 kill_collision();
83 }
84
85 return ABORT_MOVE;
86}
87
88LeafShot::LeafShot(const ReaderMapping& reader) :
89 KamikazeSnowball(reader)
90{
91 m_sprite = SpriteManager::current()->create("images/creatures/leafshot/leafshot.sprite");
92}
93
94void
95LeafShot::initialize()
96{
97 m_physic.set_velocity_x(m_dir == Direction::LEFT ? -LEAFSHOT_SPEED : LEAFSHOT_SPEED);
98 m_physic.enable_gravity(false);
99 m_sprite->set_action(m_dir == Direction::LEFT ? "left" : "right");
100}
101
102bool
103LeafShot::is_freezable() const
104{
105 return true;
106}
107
108bool
109LeafShot::collision_squished(GameObject& object)
110{
111 m_sprite->set_action(m_dir == Direction::LEFT ? "squished-left" : "squished-right");
112 // Spawn death particles
113 spawn_explosion_sprites(3, "images/objects/particles/leafshot.sprite");
114 kill_squished(object);
115 return true;
116}
117
118/* EOF */
119