Explosions light up immediate area
authorLMH <lmh.0013@gmail.com>
Fri, 30 Mar 2012 21:12:30 +0000 (11:12 -1000)
committerLMH <lmh.0013@gmail.com>
Tue, 9 Apr 2013 04:44:16 +0000 (18:44 -1000)
data/images/objects/lightmap_light/lightmap_light-large.png [new file with mode: 0644]
data/images/objects/lightmap_light/lightmap_light-large.sprite [new file with mode: 0644]
src/object/explosion.cpp
src/object/explosion.hpp

diff --git a/data/images/objects/lightmap_light/lightmap_light-large.png b/data/images/objects/lightmap_light/lightmap_light-large.png
new file mode 100644 (file)
index 0000000..53662bc
Binary files /dev/null and b/data/images/objects/lightmap_light/lightmap_light-large.png differ
diff --git a/data/images/objects/lightmap_light/lightmap_light-large.sprite b/data/images/objects/lightmap_light/lightmap_light-large.sprite
new file mode 100644 (file)
index 0000000..94ee84c
--- /dev/null
@@ -0,0 +1,7 @@
+(supertux-sprite
+    (action
+      (name "default")
+      (images "lightmap_light-large.png")
+      (hitbox 512 512 0 0)
+    )
+)
index d9e806c..3af1c15 100644 (file)
@@ -22,6 +22,8 @@
 #include "math/random_generator.hpp"
 #include "object/player.hpp"
 #include "object/sprite_particle.hpp"
+#include "sprite/sprite.hpp"
+#include "sprite/sprite_manager.hpp"
 #include "supertux/object_factory.hpp"
 #include "supertux/sector.hpp"
 
@@ -31,19 +33,27 @@ Explosion::Explosion(const Vector& pos) :
   MovingSprite(pos, "images/objects/explosion/explosion.sprite", LAYER_OBJECTS+40, COLGROUP_MOVING),
   hurt(true),
   push(false),
-  state(STATE_WAITING)
+  state(STATE_WAITING),
+  light(0.0f,0.0f,0.0f),
+  lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-large.sprite"))
 {
   sound_manager->preload("sounds/explosion.wav");
   set_pos(get_pos() - (get_bbox().get_middle() - get_pos()));
+  lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+  lightsprite->set_color(Color(0.6f, 0.6f, 0.6f));
 }
 
 Explosion::Explosion(const Reader& reader) :
   MovingSprite(reader, "images/objects/explosion/explosion.sprite", LAYER_OBJECTS+40, COLGROUP_MOVING),
   hurt(true),
   push(false),
-  state(STATE_WAITING)
+  state(STATE_WAITING),
+  light(0.0f,0.0f,0.0f),
+  lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-large.sprite"))
 {
   sound_manager->preload("sounds/explosion.wav");
+  lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+  lightsprite->set_color(Color(0.6f, 0.6f, 0.6f));
 }
 
 void
@@ -123,6 +133,21 @@ Explosion::update(float )
   }
 }
 
+void
+Explosion::draw(DrawingContext& context)
+{
+  //Draw the Sprite.
+  sprite->draw(context, get_pos(), LAYER_OBJECTS+40);
+  //Explosions produce light (if ambient light is not maxed)
+  context.get_light( get_bbox().get_middle(), &light);
+  if (light.red + light.green + light.blue < 3.0){
+    context.push_target();
+    context.set_target(DrawingContext::LIGHTMAP);
+    lightsprite->draw(context, get_bbox().get_middle(), 0);
+    context.pop_target();
+  }
+}
+
 HitResponse
 Explosion::collision(GameObject& other, const CollisionHit& )
 {
index 869b982..3e46ef4 100644 (file)
@@ -32,6 +32,7 @@ public:
   Explosion(const Reader& reader);
 
   void update(float elapsed_time);
+  void draw(DrawingContext& context);
   HitResponse collision(GameObject& other, const CollisionHit& hit);
 
   bool hurts (void) const
@@ -68,6 +69,8 @@ private:
   bool hurt;
   bool push;
   State state;
+  Color light;
+  SpritePtr lightsprite;
 
 };