1 // SuperTux badguy - Ghostflame a flame-like enemy that cannot be killed
2 // Copyright (C) 2013 LMH <lmh.0013@gmail.com>
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/ghostflame.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 Ghostflame::Ghostflame(const Reader& reader) :
31 BadGuy(reader, "images/creatures/flame/ghostflame.sprite", LAYER_FLOATINGOBJECTS),
35 light(0.0f,0.0f,0.0f),
36 lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-small.sprite"))
38 reader.get("radius", radius);
39 reader.get("speed", speed);
40 bbox.set_pos(Vector(start_position.x + cos(angle) * radius,
41 start_position.y + sin(angle) * radius));
43 //TODO: get unique death sound
44 sound_manager->preload("sounds/fizz.wav");
46 set_colgroup_active(COLGROUP_TOUCHABLE);
48 lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
49 lightsprite->set_color(Color(0.21f, 0.00f, 0.21f));
54 Ghostflame::active_update(float elapsed_time)
56 angle = fmodf(angle + elapsed_time * speed, (float) (2*M_PI));
57 Vector newpos(start_position.x + cos(angle) * radius,
58 start_position.y + sin(angle) * radius);
59 movement = newpos - get_pos();
64 Ghostflame::draw(DrawingContext& context)
67 sprite->draw(context, get_pos(), LAYER_OBJECTS);
68 //Draw the light if dark
69 context.get_light( get_bbox().get_middle(), &light );
70 if (light.blue + light.red < 2.0){
71 context.push_target();
72 context.set_target(DrawingContext::LIGHTMAP);
73 sprite->draw(context, get_pos(), layer);
74 lightsprite->draw(context, get_bbox().get_middle(), 0);
81 Ghostflame::kill_fall()