From: LMH Date: Fri, 30 Mar 2012 21:12:30 +0000 (-1000) Subject: Explosions light up immediate area X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=3918a884872e4e92805cf1476bd59db5ebf41431;p=supertux.git Explosions light up immediate area --- 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 index 000000000..53662bc55 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 index 000000000..94ee84c22 --- /dev/null +++ b/data/images/objects/lightmap_light/lightmap_light-large.sprite @@ -0,0 +1,7 @@ +(supertux-sprite + (action + (name "default") + (images "lightmap_light-large.png") + (hitbox 512 512 0 0) + ) +) diff --git a/src/object/explosion.cpp b/src/object/explosion.cpp index d9e806ca4..3af1c15e0 100644 --- a/src/object/explosion.cpp +++ b/src/object/explosion.cpp @@ -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& ) { diff --git a/src/object/explosion.hpp b/src/object/explosion.hpp index 869b982fa..3e46ef453 100644 --- a/src/object/explosion.hpp +++ b/src/object/explosion.hpp @@ -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; };