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/flame.hpp" |
18 | |
19 | #include "audio/sound_manager.hpp" |
20 | #include "audio/sound_source.hpp" |
21 | #include "editor/editor.hpp" |
22 | #include "math/util.hpp" |
23 | #include "object/sprite_particle.hpp" |
24 | #include "sprite/sprite.hpp" |
25 | #include "supertux/sector.hpp" |
26 | #include "util/reader_mapping.hpp" |
27 | |
28 | static const std::string FLAME_SOUND = "sounds/flame.wav" ; |
29 | |
30 | Flame::Flame(const ReaderMapping& reader) : |
31 | BadGuy(reader, "images/creatures/flame/flame.sprite" , LAYER_FLOATINGOBJECTS, |
32 | "images/objects/lightmap_light/lightmap_light-small.sprite" ), |
33 | angle(0), |
34 | radius(), |
35 | speed(), |
36 | sound_source() |
37 | { |
38 | reader.get("radius" , radius, 100.0f); |
39 | reader.get("speed" , speed, 2.0f); |
40 | if (!Editor::is_active()) { |
41 | m_col.m_bbox.set_pos(Vector(m_start_position.x + cosf(angle) * radius, |
42 | m_start_position.y + sinf(angle) * radius)); |
43 | } |
44 | m_countMe = false; |
45 | SoundManager::current()->preload(FLAME_SOUND); |
46 | |
47 | set_colgroup_active(COLGROUP_TOUCHABLE); |
48 | |
49 | m_lightsprite->set_color(Color(0.21f, 0.13f, 0.08f)); |
50 | m_glowing = true; |
51 | } |
52 | |
53 | ObjectSettings |
54 | Flame::get_settings() |
55 | { |
56 | ObjectSettings result = BadGuy::get_settings(); |
57 | |
58 | result.add_float(_("Radius" ), &radius, "radius" , 100.0f); |
59 | result.add_float(_("Speed" ), &speed, "speed" , 2.0f); |
60 | |
61 | result.reorder({"speed" , "sprite" , "x" , "y" }); |
62 | |
63 | return result; |
64 | } |
65 | |
66 | void |
67 | Flame::active_update(float dt_sec) |
68 | { |
69 | angle = fmodf(angle + dt_sec * speed, math::TAU); |
70 | if (!Editor::is_active()) { |
71 | Vector newpos(m_start_position.x + cosf(angle) * radius, |
72 | m_start_position.y + sinf(angle) * radius); |
73 | m_col.m_movement = newpos - get_pos(); |
74 | sound_source->set_position(get_pos()); |
75 | } |
76 | |
77 | if (m_sprite->get_action() == "fade" && m_sprite->animation_done()) remove_me(); |
78 | } |
79 | |
80 | void |
81 | Flame::activate() |
82 | { |
83 | if (Editor::is_active()) |
84 | return; |
85 | sound_source = SoundManager::current()->create_sound_source(FLAME_SOUND); |
86 | sound_source->set_position(get_pos()); |
87 | sound_source->set_looping(true); |
88 | sound_source->set_gain(1.0f); |
89 | sound_source->set_reference_distance(32); |
90 | sound_source->play(); |
91 | } |
92 | |
93 | void |
94 | Flame::deactivate() |
95 | { |
96 | sound_source.reset(); |
97 | } |
98 | |
99 | |
100 | void |
101 | Flame::kill_fall() |
102 | { |
103 | } |
104 | |
105 | void |
106 | Flame::freeze() |
107 | { |
108 | SoundManager::current()->play("sounds/sizzle.ogg" , get_pos()); |
109 | m_sprite->set_action("fade" , 1); |
110 | Sector::get().add<SpriteParticle>("images/objects/particles/smoke.sprite" , |
111 | "default" , |
112 | m_col.m_bbox.get_middle(), ANCHOR_MIDDLE, |
113 | Vector(0, -150), Vector(0,0), LAYER_BACKGROUNDTILES+2); |
114 | set_group(COLGROUP_DISABLED); |
115 | |
116 | // start dead-script |
117 | run_dead_script(); |
118 | } |
119 | |
120 | bool |
121 | Flame::is_freezable() const |
122 | { |
123 | return true; |
124 | } |
125 | |
126 | bool |
127 | Flame::is_flammable() const |
128 | { |
129 | return false; |
130 | } |
131 | |
132 | void Flame::stop_looping_sounds() |
133 | { |
134 | if (sound_source) { |
135 | sound_source->stop(); |
136 | } |
137 | } |
138 | |
139 | void Flame::play_looping_sounds() |
140 | { |
141 | if (sound_source) { |
142 | sound_source->play(); |
143 | } |
144 | } |
145 | |
146 | /* EOF */ |
147 | |