From d64bdf284d161cc04cb08dff732978f74d73d78e Mon Sep 17 00:00:00 2001 From: LMH Date: Sun, 9 Nov 2014 10:25:00 -1000 Subject: [PATCH] Code structure for basic earthflower ability: illumination in the dark --- src/object/player.cpp | 11 +++++++++++ src/object/player.hpp | 2 ++ 2 files changed, 13 insertions(+) diff --git a/src/object/player.cpp b/src/object/player.cpp index cc4dfcf1c..e1316d25b 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -127,6 +127,8 @@ Player::Player(PlayerStatus* _player_status, const std::string& name_) : jump_early_apex(), on_ice(), ice_this_frame(), + light(1.0f,1.0f,1.0f), + lightsprite(SpriteManager::current()->create("images/objects/lightmap_light/lightmap_light-tiny.sprite")), dir(), old_dir(), last_ground_y(), @@ -219,6 +221,7 @@ Player::init() on_ice = false; ice_this_frame = false; speedlimit = 0; //no special limit + lightsprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); on_ground_flag = false; grabbed_object = NULL; @@ -1195,6 +1198,14 @@ Player::draw(DrawingContext& context) ; // don't draw Tux else { sprite->draw(context, get_pos(), LAYER_OBJECTS + 1); + // illuminate Tux in dark areas with earthflower bonus + context.get_light( get_bbox().get_middle(), &light ); + if (light.red + light.green + light.blue < 3.0 && player_status->bonus == EARTH_BONUS){ + context.push_target(); + context.set_target(DrawingContext::LIGHTMAP); + lightsprite->draw(context, get_pos() + Vector(dir==LEFT ? 0 : 32, 0), 0); + context.pop_target(); + } } } diff --git a/src/object/player.hpp b/src/object/player.hpp index 3dda1fd75..2e72b523a 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -280,6 +280,8 @@ private: bool jump_early_apex; bool on_ice; bool ice_this_frame; + Color light; + SpritePtr lightsprite; public: Direction dir; -- 2.11.0