1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.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/yeti_stalactite.hpp"
18
19#include "editor/editor.hpp"
20#include "sprite/sprite.hpp"
21
22static const float YT_SHAKE_TIME = .8f;
23
24YetiStalactite::YetiStalactite(const ReaderMapping& mapping) :
25 Stalactite(mapping)
26{
27}
28
29void
30YetiStalactite::start_shaking()
31{
32 timer.start(YT_SHAKE_TIME);
33 state = STALACTITE_SHAKING;
34 if ((static_cast<int>(get_pos().x) / 32) % 2 == 0) {
35 m_physic.set_velocity_y(100);
36 }
37}
38
39bool
40YetiStalactite::is_hanging() const
41{
42 return state == STALACTITE_HANGING;
43}
44
45void
46YetiStalactite::active_update(float dt_sec)
47{
48 if (state == STALACTITE_HANGING)
49 return;
50
51 Stalactite::active_update(dt_sec);
52}
53
54void
55YetiStalactite::update(float dt_sec)
56{
57 // Respawn instead of removing once squished
58 if (get_state() == STATE_SQUISHED && check_state_timer()) {
59 set_state(STATE_ACTIVE);
60 state = STALACTITE_HANGING;
61 // Hopefully we shouldn't come into contact with anything...
62 m_sprite->set_action("normal");
63 set_pos(m_start_position);
64 set_colgroup_active(COLGROUP_TOUCHABLE);
65 }
66
67 // Call back to badguy to do normal stuff
68 BadGuy::update(dt_sec);
69}
70
71void
72YetiStalactite::draw(DrawingContext& context)
73{
74 if (Editor::is_active() &&
75 m_sprite->get_action() != "yeti-stalactite" &&
76 m_sprite->has_action("yeti-stalactite"))
77 {
78 m_sprite->set_action("yeti-stalactite");
79 BadGuy::draw(context);
80 return;
81 }
82 else
83 {
84 Stalactite::draw(context);
85 }
86}
87
88bool
89YetiStalactite::is_flammable() const
90{
91 return false;
92}
93
94/* EOF */
95