2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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/>.
17 #include "badguy/flame.hpp"
21 #include "audio/sound_manager.hpp"
22 #include "math/random_generator.hpp"
23 #include "sprite/sprite.hpp"
24 #include "sprite/sprite_manager.hpp"
25 #include "object/sprite_particle.hpp"
26 #include "supertux/object_factory.hpp"
27 #include "supertux/sector.hpp"
28 #include "util/reader.hpp"
30 static const std::string FLAME_SOUND = "sounds/flame.wav";
32 Flame::Flame(const Reader& reader) :
33 BadGuy(reader, "images/creatures/flame/flame.sprite", LAYER_FLOATINGOBJECTS),
37 light(0.0f,0.0f,0.0f),
38 lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-small.sprite")),
41 reader.get("radius", radius);
42 reader.get("speed", speed);
43 bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
44 start_position.y + sin(angle) * radius));
46 SoundManager::current()->preload(FLAME_SOUND);
48 set_colgroup_active(COLGROUP_TOUCHABLE);
50 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
51 lightsprite->set_color(Color(0.21f, 0.13f, 0.08f));
55 Flame::active_update(float elapsed_time)
57 angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
58 Vector newpos(start_position.x + cos(angle) * radius,
59 start_position.y + sin(angle) * radius);
60 movement = newpos - get_pos();
62 sound_source->set_position(get_pos());
64 if (sprite->get_action() == "fade" && sprite->animation_done()) remove_me();
68 Flame::draw(DrawingContext& context)
71 sprite->draw(context, get_pos(), LAYER_OBJECTS);
72 //Draw the light if dark
74 context.get_light( get_bbox().get_middle(), &light );
75 if (light.red + light.green < 2.0){
76 context.push_target();
77 context.set_target(DrawingContext::LIGHTMAP);
78 sprite->draw(context, get_pos(), layer);
79 lightsprite->draw(context, get_bbox().get_middle(), 0);
88 sound_source = SoundManager::current()->create_sound_source(FLAME_SOUND);
89 sound_source->set_position(get_pos());
90 sound_source->set_looping(true);
91 sound_source->set_gain(2.0);
92 sound_source->set_reference_distance(32);
111 SoundManager::current()->play("sounds/sizzle.ogg", get_pos());
112 sprite->set_action("fade", 1);
113 Sector::current()->add_object(std::make_shared<SpriteParticle>("images/objects/particles/smoke.sprite",
115 bbox.get_middle(), ANCHOR_MIDDLE,
116 Vector(0, -150), Vector(0,0), LAYER_BACKGROUNDTILES+2));
117 set_group(COLGROUP_DISABLED);
124 Flame::is_freezable() const