X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fcandle.cpp;h=98c48c1953f1a8c450dbe23b57bd4bcca46d8515;hb=1dfbd27a41341f26775ca4e2b9ca4864f5744a6f;hp=924bc38a3408f71a81ee553959fbf437503cffc0;hpb=8a627e73d824b5a14249cfe066dc2fdc643ce28d;p=supertux.git diff --git a/src/object/candle.cpp b/src/object/candle.cpp index 924bc38a3..98c48c195 100644 --- a/src/object/candle.cpp +++ b/src/object/candle.cpp @@ -25,10 +25,14 @@ #include "sector.hpp" #include "object/sprite_particle.hpp" #include "object_factory.hpp" +#include "random_generator.hpp" Candle::Candle(const lisp::Lisp& lisp) - : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true) + : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true), + candle_light_1("images/objects/candle/candle-light-1.png"), + candle_light_2("images/objects/candle/candle-light-2.png") { + lisp.get("name", name); lisp.get("burning", burning); if (burning) { @@ -36,6 +40,28 @@ Candle::Candle(const lisp::Lisp& lisp) } else { sprite->set_action("off"); } + +} + +void +Candle::draw(DrawingContext& context) +{ + // draw regular sprite + sprite->draw(context, get_pos(), layer); + + // draw on lightmap + if (burning) { + 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 (systemRandom.rand(10) != 0) { + context.draw_surface(&candle_light_1, pos, layer); + } else { + context.draw_surface(&candle_light_2, pos, layer); + } + context.pop_target(); + } } HitResponse