1 // SuperTux
2 // Copyright (C) 2015 Hume2 <teratux.mail@gmail.com>
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/walking_candle.hpp"
18
19 #include "object/lantern.hpp"
20 #include "sprite/sprite.hpp"
21 #include "util/reader_mapping.hpp"
22
WalkingCandle(const ReaderMapping & reader)23 WalkingCandle::WalkingCandle(const ReaderMapping& reader)
24 : WalkingBadguy(reader, "images/creatures/mr_candle/mr-candle.sprite", "left", "right"),
25 lightcolor(1, 1, 1)
26 {
27 walk_speed = 80;
28 max_drop_height = 64;
29
30 std::vector<float> vColor;
31 if (reader.get("color", vColor)) {
32 lightcolor = Color(vColor);
33 }
34 m_sprite->set_color(lightcolor);
35 m_lightsprite->set_color(lightcolor);
36
37 m_countMe = false;
38 m_glowing = true;
39 }
40
41 bool
is_freezable() const42 WalkingCandle::is_freezable() const
43 {
44 return true;
45 }
46
47 bool
is_flammable() const48 WalkingCandle::is_flammable() const
49 {
50 return m_frozen;
51 }
52
53 void
freeze()54 WalkingCandle::freeze() {
55 BadGuy::freeze();
56 m_glowing = false;
57 }
58
59 void
unfreeze()60 WalkingCandle::unfreeze() {
61 BadGuy::unfreeze();
62 m_glowing = true;
63 }
64
65 HitResponse
collision(GameObject & other,const CollisionHit & hit)66 WalkingCandle::collision(GameObject& other, const CollisionHit& hit) {
67 auto l = dynamic_cast<Lantern*>(&other);
68 if (l && !m_frozen) if (l->get_bbox().get_bottom() < m_col.m_bbox.get_top()) {
69 l->add_color(lightcolor);
70 run_dead_script();
71 remove_me();
72 return FORCE_MOVE;
73 }
74 return WalkingBadguy::collision(other, hit);
75 }
76
77 ObjectSettings
get_settings()78 WalkingCandle::get_settings()
79 {
80 ObjectSettings result = BadGuy::get_settings();
81
82 result.add_color(_("Color"), &lightcolor, "color", Color::WHITE);
83
84 result.reorder({"color", "x", "y"});
85
86 return result;
87 }
88
89 void
after_editor_set()90 WalkingCandle::after_editor_set()
91 {
92 WalkingBadguy::after_editor_set();
93
94 m_sprite->set_color(lightcolor);
95 m_lightsprite->set_color(lightcolor);
96 }
97
98 /* EOF */
99