Skip to content

Commit

Permalink
Explosions light up immediate area
Browse files Browse the repository at this point in the history
  • Loading branch information
LMH0013 committed Apr 9, 2013
1 parent 550dce7 commit 3918a88
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,7 @@
(supertux-sprite
(action
(name "default")
(images "lightmap_light-large.png")
(hitbox 512 512 0 0)
)
)
29 changes: 27 additions & 2 deletions src/object/explosion.cpp
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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& )
{
Expand Down
3 changes: 3 additions & 0 deletions src/object/explosion.hpp
Expand Up @@ -32,6 +32,7 @@ class Explosion : public MovingSprite
Explosion(const Reader& reader);

void update(float elapsed_time);
void draw(DrawingContext& context);
HitResponse collision(GameObject& other, const CollisionHit& hit);

bool hurts (void) const
Expand Down Expand Up @@ -68,6 +69,8 @@ class Explosion : public MovingSprite
bool hurt;
bool push;
State state;
Color light;
SpritePtr lightsprite;

};

Expand Down

0 comments on commit 3918a88

Please sign in to comment.