#include "util/reader.hpp"
Candle::Candle(const Reader& lisp)
- : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true),
- candle_light_1(Surface::create("images/objects/candle/candle-light-1.png")),
- candle_light_2(Surface::create("images/objects/candle/candle-light-2.png"))
+ : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED),
+ burning(true),
+ flicker(true),
+ lightcolor(1.0f, 1.0f, 1.0f),
+ candle_light_1(sprite_manager->create("images/objects/candle/candle-light-1.sprite")),
+ candle_light_2(sprite_manager->create("images/objects/candle/candle-light-2.sprite"))
{
lisp.get("name", name);
lisp.get("burning", burning);
-
+ lisp.get("flicker", flicker);
+ //get color from lisp
+ std::vector<float> vColor;
+ lisp.get("color", vColor);
+ if (vColor.size() >= 3) {
+ lightcolor = Color(vColor);
+ candle_light_1->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+ candle_light_2->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+ candle_light_1->set_color(lightcolor);
+ candle_light_2->set_color(lightcolor);
+ }
+
if (burning) {
sprite->set_action("on");
} else {
// draw on lightmap
if (burning) {
- Vector pos = get_pos() + (bbox.get_size() - candle_light_1->get_size()) / 2;
+ //Vector pos = get_pos() + (bbox.get_size() - candle_light_1->get_size()) / 2;
context.push_target();
context.set_target(DrawingContext::LIGHTMAP);
// draw approx. 1 in 10 frames darker. Makes the candle flicker
- if (gameRandom.rand(10) != 0) {
- context.draw_surface(candle_light_1, pos, layer);
+ if (gameRandom.rand(10) != 0 || !flicker) {
+ //context.draw_surface(candle_light_1, pos, layer);
+ candle_light_1->draw(context, get_bbox().get_middle(), 0);
} else {
- context.draw_surface(candle_light_2, pos, layer);
+ //context.draw_surface(candle_light_2, pos, layer);
+ candle_light_2->draw(context, get_bbox().get_middle(), 0);
}
context.pop_target();
}
this->burning = burning;
if (burning) {
sprite->set_action("on");
- puff_smoke();
} else {
sprite->set_action("off");
- puff_smoke();
}
+ //puff smoke for flickering light sources only
+ if (flicker) puff_smoke();
}
/* EOF */