1 //  SuperTux - Crystallo
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/crystallo.hpp"
18 
19 #include "util/reader_mapping.hpp"
20 
Crystallo(const ReaderMapping & reader)21 Crystallo::Crystallo(const ReaderMapping& reader) :
22   WalkingBadguy(reader, "images/creatures/crystallo/crystallo.sprite", "left", "right"),
23   m_radius()
24 {
25   walk_speed = 80;
26   max_drop_height = 16;
27   reader.get("radius", m_radius, 100.0f);
28 }
29 
30 ObjectSettings
get_settings()31 Crystallo::get_settings()
32 {
33   ObjectSettings result = WalkingBadguy::get_settings();
34 
35   result.add_float(_("Radius"), &m_radius, "radius", 100.0f);
36 
37   result.reorder({"radius", "direction", "x", "y"});
38 
39   return result;
40 }
41 
42 void
active_update(float dt_sec)43 Crystallo::active_update(float dt_sec)
44 {
45   //walking and turning properly
46   float targetwalk = m_dir == Direction::LEFT ? -80.f : 80.f;
47   if (m_dir != Direction::LEFT && get_pos().x > (m_start_position.x + m_radius - 20.f))
48     targetwalk = -80.f;
49   if (m_dir != Direction::RIGHT && get_pos().x < (m_start_position.x - m_radius + 20.f))
50     targetwalk = 80.f;
51   set_action(std::abs(m_physic.get_velocity_x()) < 80.f ?
52     m_dir == Direction::LEFT ? "slowdown-left" : "slowdown-right" :
53     m_dir == Direction::LEFT ? "left" : "right", -1);
54   WalkingBadguy::active_update(dt_sec, targetwalk, 2.f);
55 }
56 
57 bool
collision_squished(GameObject & object)58 Crystallo::collision_squished(GameObject& object)
59 {
60   set_action(m_dir == Direction::LEFT ? "shattered-left" : "shattered-right", /* loops = */ -1, ANCHOR_BOTTOM);
61   kill_squished(object);
62   m_physic.set_gravity_modifier(1.f);
63   m_physic.set_velocity_x(0.0);
64   m_physic.set_acceleration_x(0.0);
65   return true;
66 }
67 
68 bool
is_flammable() const69 Crystallo::is_flammable() const
70 {
71   return false;
72 }
73 
74 /* EOF */
75