Candle made more versatile: flicker can be disabled and RGB light color chosen
authorLMH <lmh.0013@gmail.com>
Mon, 27 Feb 2012 03:54:47 +0000 (17:54 -1000)
committerLMH <lmh.0013@gmail.com>
Tue, 9 Apr 2013 04:44:15 +0000 (18:44 -1000)
data/images/objects/candle/candle-light-1.sprite [new file with mode: 0644]
data/images/objects/candle/candle-light-2.sprite [new file with mode: 0644]
src/object/candle.cpp
src/object/candle.hpp

diff --git a/data/images/objects/candle/candle-light-1.sprite b/data/images/objects/candle/candle-light-1.sprite
new file mode 100644 (file)
index 0000000..f4d4100
--- /dev/null
@@ -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 (file)
index 0000000..42a6ad8
--- /dev/null
@@ -0,0 +1,7 @@
+(supertux-sprite
+    (action
+      (name "default")
+      (images "candle-light-2.png")
+      (hitbox 256 256 0 0)
+    )
+)
index fe140f2..9a39cd0 100644 (file)
 #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 {
@@ -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 */
index 4b7146c..4ea74ba 100644 (file)
@@ -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) */
 
 };