From 42570f1f8f28f5b53c751e47fb9a701c6106900e Mon Sep 17 00:00:00 2001 From: LMH Date: Wed, 29 Feb 2012 20:35:41 -1000 Subject: [PATCH] Powerups glow in the dark --- .../objects/lightmap_light/lightmap_light-tiny.png | Bin 0 -> 2027 bytes .../lightmap_light/lightmap_light-tiny.sprite | 7 ++ data/levels/test/glow_effects.stl | 100 +++++++++++++++++++++ src/object/flower.cpp | 19 +++- src/object/flower.hpp | 4 +- src/object/growup.cpp | 23 ++++- src/object/growup.hpp | 3 + src/object/star.cpp | 23 ++++- src/object/star.hpp | 3 + 9 files changed, 177 insertions(+), 5 deletions(-) create mode 100644 data/images/objects/lightmap_light/lightmap_light-tiny.png create mode 100644 data/images/objects/lightmap_light/lightmap_light-tiny.sprite create mode 100755 data/levels/test/glow_effects.stl 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 0000000000000000000000000000000000000000..efeadd28db41b319a7173d730f97faf02bed0c1b GIT binary patch literal 2027 zcmVJNRA>e5m}{4tMi4~NdS8nD|9@$0?^8gt{zV4D8x+wS)SIG!1|JN}NXGlnjkSzs@XnkoDpDwj;1u$ZCgz5cCx0lxlC z*U|WtKtm7ET@j!`WIgs+;50~#;}s;czzP8J0C0Y z0fB8|0S015TTXg~lDf!FD^2)s6(p~cx?+$N0UIK$(iKHpCF1#gppIz$8D zfx&BmAwYX6qFmk8-RgBbL*azLB0U}o2Drcbg$Q@Z2l9Zt7yf;Q1=xlIka%lty6b5+ zYzWNo!*`%*5B+=SW0W8l2-9vMK=cKEo@mf~F8G)3H8suZyrr-ru)yOz5f}ckU>~N( zY8;_rKp+6sp#TAZ!1MG}jb2aHgFg0quf7MmuPH19R`5ptuE79)oc7f`dt3-42xYa* zl72@0rC=fYvs^G)QHjm{35A6~cQErIfcN^npZ;h9lGrx^yo-5E4+2Q9P6Qwt(I-`s z-pAuED$E4R|A6bi@PO{8uSJ1|3j5joM+BbAdnYZ@(BGk|HxEU*9(e-sejy8vdQ($n)wT`434`p?utxVpuhDV70d)u(W%HZ zGz6v~3Fy7ZA8-qj1S$_}6hSF7(=7j>knB$YAYqFJ_;^=j0b!%|I|g1@4 z1&;=|Ex(KFy7-Vtc#H7pkT86$YbKc#LLhTsq$l-(mhx!U?USQxslRLp?<6T=m5dmk^`0tbHES?Zw){N6EU;lp+@3;GW@hb>dJC?CadcDc~tgmT)QJ>>PxIzHR3Px`#Nv(@4Ope2b>j%ymg5+IYFbSgoK`;@eU_OKfGr)xBj5!HpCP>0yI46>r=FAp${g1@FZD2+)HqGD$e#s%{G4RpAR73@T zhC~{l!9#_72)LjMFSOndw@ZPf&>-QO0Flg#DDnk_Pc~DYB%4Lt?;n+=b+N)a}T}*9#`3_*t#{14o zu}{cOiR2D%20Wbdi0VklM-4FS*>+qFxnKa+@Bj8AsbT|V>Pp?@p1wj6@s5x1earZ{G-~>ZoHs9&t!DQFbF>r zKBquL7dqfBBYE7oU(y#~xA%to*#w{g5y=cK2m~6ScvFV}z8HiN0K8u>q=EMx;I$t$ zP{cZkPh<*YpBnmm?}6t%NiE2P0pAMLWBIP$PzoNyd`95$ns<5^QYegvD8LL8U<5^4 zdGto+LE!sj8yZM}PdB9Dyd?x`@LoPaA;?&S zU`D9Gk^{V;7J-ch1i@w0RXiUd00|7wdLh7USQ8`ZXb_MD6u2@7jEPv>RiM*hHk5_b z2NE;gNeVe5?L#IM*93SBB?M#ven$i0AwUMi|M@dT6KD;TcvoHcs00lYOo{a#2p+Q` zU~Yr})gOsTLjVZ_8kmfvVFJJmsCM#wpeO)@(0ODCJl!qOc)u@G27vqs$pi-iP$23~ zL? 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 -- 2.11.0