From: LMH Date: Mon, 27 Feb 2012 03:54:47 +0000 (-1000) Subject: Candle made more versatile: flicker can be disabled and RGB light color chosen X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=72a0475f9ef0bda6fffcd7109eb435624c86e271;p=supertux.git Candle made more versatile: flicker can be disabled and RGB light color chosen --- diff --git a/data/images/objects/candle/candle-light-1.sprite b/data/images/objects/candle/candle-light-1.sprite new file mode 100644 index 000000000..f4d410090 --- /dev/null +++ b/data/images/objects/candle/candle-light-1.sprite @@ -0,0 +1,7 @@ +(supertux-sprite + (action + (name "default") + (images "candle-light-1.png") + (hitbox 256 256 0 0) + ) +) diff --git a/data/images/objects/candle/candle-light-2.sprite b/data/images/objects/candle/candle-light-2.sprite new file mode 100644 index 000000000..42a6ad840 --- /dev/null +++ b/data/images/objects/candle/candle-light-2.sprite @@ -0,0 +1,7 @@ +(supertux-sprite + (action + (name "default") + (images "candle-light-2.png") + (hitbox 256 256 0 0) + ) +) diff --git a/src/object/candle.cpp b/src/object/candle.cpp index fe140f2bb..9a39cd01a 100644 --- a/src/object/candle.cpp +++ b/src/object/candle.cpp @@ -24,13 +24,27 @@ #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 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 { @@ -47,14 +61,16 @@ Candle::draw(DrawingContext& context) // 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(); } @@ -103,11 +119,11 @@ Candle::set_burning(bool burning) 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 */ diff --git a/src/object/candle.hpp b/src/object/candle.hpp index 4b7146cc5..4ea74bab9 100644 --- a/src/object/candle.hpp +++ b/src/object/candle.hpp @@ -48,8 +48,10 @@ public: private: bool burning; /**< true if candle is currently lighted */ - SurfacePtr candle_light_1; /**< drawn to lightmap */ - SurfacePtr candle_light_2; /**< drawn to lightmap (alternative image) */ + bool flicker; /**< true if candle light is to flicker */ + Color lightcolor; /**< determines color or light given off */ + SpritePtr candle_light_1; /**< drawn to lightmap */ + SpritePtr candle_light_2; /**< drawn to lightmap (alternative image) */ };