From: LMH Date: Thu, 1 Mar 2012 06:35:41 +0000 (-1000) Subject: Powerups glow in the dark X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=42570f1f8f28f5b53c751e47fb9a701c6106900e;p=supertux.git Powerups glow in the dark --- diff --git a/data/images/objects/lightmap_light/lightmap_light-tiny.png b/data/images/objects/lightmap_light/lightmap_light-tiny.png new file mode 100644 index 000000000..efeadd28d Binary files /dev/null and b/data/images/objects/lightmap_light/lightmap_light-tiny.png differ diff --git a/data/images/objects/lightmap_light/lightmap_light-tiny.sprite b/data/images/objects/lightmap_light/lightmap_light-tiny.sprite new file mode 100644 index 000000000..841be38c5 --- /dev/null +++ b/data/images/objects/lightmap_light/lightmap_light-tiny.sprite @@ -0,0 +1,7 @@ +(supertux-sprite + (action + (name "default") + (images "lightmap_light-tiny.png") + (hitbox 32 32 0 0) + ) +) diff --git a/data/levels/test/glow_effects.stl b/data/levels/test/glow_effects.stl new file mode 100755 index 000000000..58ac63ac2 --- /dev/null +++ b/data/levels/test/glow_effects.stl @@ -0,0 +1,100 @@ +(supertux-level + (version 2) + (name (_ "Glow Effects Test")) + (author "LMH") + (license "GPL 2 / CC-by-sa 3.0" ) + (sector (name "main" ) + (ambient-light 0.02 0.02 0.02 ) + (camera (mode "normal" )) + (music "music/voc-dark.ogg" ) + + (spawnpoint (name "main" ) + (x 64 )(y 448 )) + + (mrbomb (x 832 )(y 736 )) + (short_fuse (x 1056 )(y 736 )) + (short_fuse (x 1152 )(y 736 )) + (short_fuse (x 1248 )(y 736 )) + (haywire (x 928 )(y 736 )) + (flame (x 1088 )(y 512 )) + (flame (x 1088 )(y 512 )) + (flame (x 1088 )(y 512 )) + + (tilemap (name "Interactive" ) + (z-pos 0 )(solid #t ) + (width 42 )(height 30 ) + (tiles ; 160 192 224 256 288 320 352 384 416 448 480 512 544 576 608 640 672 704 736 768 800 832 864 896 928 960 992 1024 1056 1088 1120 1152 1184 1216 1248 1280 1312 +0 0 0 0 0 0 0 0 0 0 0 0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0 ; 704 +0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 48 48 ; 736 +48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 0 0 0 0 0 0 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 ; 768 +48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 0 0 0 0 0 0 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 ; 800 +48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 0 0 0 0 0 0 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 ; 832 +48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 0 0 0 0 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 ; 864 +48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 0 0 0 0 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 ; 896 +48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 2136 2137 2138 2139 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 48 ; 928 + )) + + (candle (x 128 )(y 480 )) + (candle (x 96 )(y 736 )(color 1 0 0 )(name "red" )) + (candle (x 320 )(y 736 )(color 1 0.5 0 )(name "orange" )) + (candle (x 544 )(y 736 )(color 1 1 0 )(name "yellow" )) + (candle (x 768 )(y 736 )(color 0 1 0 )(name "green" )) + (candle (x 992 )(y 736 )(color 0 0 1 )(name "blue" )) + (candle (x 1216 )(y 736 )(color 0.5 0 0.5 )(name "purple" )) + (candle (x 1184 )(y 480 )(color 1 1 1 )) + + (candle (x 608 )(y 960 )(color 0.4 0.1 0 )(flicker #f )) + (candle (x 640 )(y 960 )(color 0.4 0.1 0 )(flicker #f )) + (candle (x 672 )(y 960 )(color 0.4 0.1 0 )(flicker #f )) + (candle (x 704 )(y 960 )(color 0.4 0.1 0 )(flicker #f )) + + (candle (x 576 )(y 320 )(color 1 0.2 0.05 )(name "torch1" )(sprite "images/objects/candle/torch/torch.sprite" )(burning #f )) + (candle (x 736 )(y 320 )(color 1 0.2 0.05 )(name "torch2" )(sprite "images/objects/candle/torch/torch.sprite" )(burning #f )) + + (switch (script " red.set_burning(!red.get_burning()); + wait( 0.1 ); + orange.set_burning(!orange.get_burning()); + wait( 0.1 ); + yellow.set_burning(!yellow.get_burning()); + wait( 0.1 ); + green.set_burning(!green.get_burning()); + wait( 0.1 ); + blue.set_burning(!blue.get_burning()); + wait( 0.1 ); + purple.set_burning(!purple.get_burning()); ")(sprite "images/objects/switch/switch.sprite" ) + (x 96 )(y 448 )) + + (switch (script " torch1.set_burning(!torch1.get_burning()); + torch2.set_burning(!torch2.get_burning()); ")(sprite "images/objects/switch/switch.sprite" ) + (x 1216 )(y 448 )) + (switch (script " settings.set_ambient_light((settings.get_ambient_red() + 0.14 > 1) ? 0.02 : settings.get_ambient_red() + 0.14 , (settings.get_ambient_green() + 0.14 > 1) ? 0.02 : settings.get_ambient_green() + 0.14 , (settings.get_ambient_blue() + 0.14 > 1) ? 0.02 : settings.get_ambient_blue() + 0.14 ); ")(sprite "images/objects/switch/switch.sprite" ) + (x 320 )(y 576 )) + + (bonusblock (x 544 )(y 352 )(contents "icegrow" )(count 0 )) + (bonusblock (x 608 )(y 352 )(contents "star" )(count 0 )) + (bonusblock (x 704 )(y 352 )(contents "1up" )(count 0 )) + (bonusblock (x 768 )(y 352 )(contents "firegrow" )(count 0 )) + +)) diff --git a/src/object/flower.cpp b/src/object/flower.cpp index eb54f9c28..fe62f289a 100644 --- a/src/object/flower.cpp +++ b/src/object/flower.cpp @@ -17,22 +17,28 @@ #include "audio/sound_manager.hpp" #include "object/flower.hpp" #include "object/player.hpp" +#include "sprite/sprite.hpp" #include "sprite/sprite_manager.hpp" Flower::Flower(BonusType _type) : type(_type), sprite(), - drawing_effect(NO_EFFECT) + drawing_effect(NO_EFFECT), + light(1.0f,1.0f,1.0f), + lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-tiny.sprite")) { bbox.set_size(32, 32); - + lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + if(type == FIRE_BONUS) { sprite = sprite_manager->create("images/powerups/fireflower/fireflower.sprite"); sound_manager->preload("sounds/fire-flower.wav"); + lightsprite->set_color(Color(0.3f, 0.0f, 0.0f)); } else if(type == ICE_BONUS) { sprite = sprite_manager->create("images/powerups/iceflower/iceflower.sprite"); sound_manager->preload("sounds/fire-flower.wav"); + lightsprite->set_color(Color(0.0f, 0.1f, 0.2f)); } else { assert(false); } @@ -52,7 +58,16 @@ Flower::update(float ) void Flower::draw(DrawingContext& context) { + //Draw the Sprite. sprite->draw(context, get_pos(), LAYER_OBJECTS, drawing_effect); + //Draw the light when dark + 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 diff --git a/src/object/flower.hpp b/src/object/flower.hpp index ec72a643f..2bba798a6 100644 --- a/src/object/flower.hpp +++ b/src/object/flower.hpp @@ -39,7 +39,9 @@ private: private: Flower(const Flower&); Flower& operator=(const Flower&); - + Color light; + SpritePtr lightsprite; + friend class FlipLevelTransformer; }; diff --git a/src/object/growup.cpp b/src/object/growup.cpp index 4990cf09b..d96cf1db1 100644 --- a/src/object/growup.cpp +++ b/src/object/growup.cpp @@ -17,14 +17,21 @@ #include "audio/sound_manager.hpp" #include "object/growup.hpp" #include "object/player.hpp" +#include "sprite/sprite.hpp" +#include "sprite/sprite_manager.hpp" GrowUp::GrowUp(Direction direction) : MovingSprite(Vector(0,0), "images/powerups/egg/egg.sprite", LAYER_OBJECTS, COLGROUP_MOVING), - physic() + physic(), + light(0.0f,0.0f,0.0f), + lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-tiny.sprite")) { physic.enable_gravity(true); physic.set_velocity_x((direction == LEFT)?-100:100); sound_manager->preload("sounds/grow.ogg"); + //set light for glow effect + lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + lightsprite->set_color(Color(0.2f, 0.2f, 0.0f)); } void @@ -34,6 +41,20 @@ GrowUp::update(float elapsed_time) } void +GrowUp::draw(DrawingContext& context){ + //Draw the Sprite. + MovingSprite::draw(context); + //Draw the light when dark + context.get_light( get_bbox().get_middle(), &light ); + if (light.red + light.green < 2.0){ + context.push_target(); + context.set_target(DrawingContext::LIGHTMAP); + lightsprite->draw(context, get_bbox().get_middle(), 0); + context.pop_target(); + } +} + +void GrowUp::collision_solid(const CollisionHit& hit) { if(hit.top) diff --git a/src/object/growup.hpp b/src/object/growup.hpp index e10266c65..f1427c028 100644 --- a/src/object/growup.hpp +++ b/src/object/growup.hpp @@ -27,12 +27,15 @@ public: GrowUp(Direction direction = RIGHT); virtual void update(float elapsed_time); + virtual void draw(DrawingContext& context); virtual void collision_solid(const CollisionHit& hit); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); void do_jump(); private: Physic physic; + Color light; + SpritePtr lightsprite; }; #endif diff --git a/src/object/star.cpp b/src/object/star.cpp index f421d4308..191ebf836 100644 --- a/src/object/star.cpp +++ b/src/object/star.cpp @@ -16,6 +16,8 @@ #include "object/player.hpp" #include "object/star.hpp" +#include "sprite/sprite.hpp" +#include "sprite/sprite_manager.hpp" static const float INITIALJUMP = -400; static const float STAR_SPEED = 150; @@ -23,9 +25,14 @@ static const float JUMPSTAR_SPEED = -300; Star::Star(const Vector& pos, Direction direction) : MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING), - physic() + physic(), + light(0.0f,0.0f,0.0f), + lightsprite(sprite_manager->create("images/objects/lightmap_light/lightmap_light-tiny.sprite")) { physic.set_velocity((direction == LEFT) ? -STAR_SPEED : STAR_SPEED, INITIALJUMP); + //set light for glow effect + lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + lightsprite->set_color(Color(0.4f, 0.4f, 0.4f)); } void @@ -35,6 +42,20 @@ Star::update(float elapsed_time) } void +Star::draw(DrawingContext& context){ + //Draw the Sprite. + MovingSprite::draw(context); + //Draw the light when dark + 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(); + } +} + +void Star::collision_solid(const CollisionHit& hit) { if(hit.bottom) { diff --git a/src/object/star.hpp b/src/object/star.hpp index f719ae189..5e1840406 100644 --- a/src/object/star.hpp +++ b/src/object/star.hpp @@ -25,11 +25,14 @@ public: Star(const Vector& pos, Direction direction = RIGHT); virtual void update(float elapsed_time); + virtual void draw(DrawingContext& context); virtual void collision_solid(const CollisionHit& hit); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); private: Physic physic; + Color light; + SpritePtr lightsprite; }; #endif