X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Fmagicblock.cpp;h=973c7646faa67edd0a89354cc6e03793c6ba6823;hb=c1277f5b7db9f55d1d28f658b4e804f32b76f0ce;hp=f424c67e47458fe83fd31643d0db19582a5dc992;hpb=df0550c02366ae190426938737a3adc9eda3f6a6;p=supertux.git diff --git a/src/object/magicblock.cpp b/src/object/magicblock.cpp index f424c67e4..973c7646f 100644 --- a/src/object/magicblock.cpp +++ b/src/object/magicblock.cpp @@ -1,18 +1,16 @@ -// $Id$ -// // SuperTux - MagicBlock // -// Magic Blocks are tile-like game objects that are sensitive to +// Magic Blocks are tile-like game objects that are sensitive to // lighting conditions. They are rendered in a color and // will only be solid as long as light of the same color shines // on the block. // // Copyright (C) 2006 Wolfgang Becker // -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -20,44 +18,57 @@ // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include -#include +// along with this program. If not, see . #include "object/camera.hpp" -#include "magicblock.hpp" -#include "object_factory.hpp" -#include "sprite/sprite_manager.hpp" -#include "sector.hpp" -#include "main.hpp" +#include "object/magicblock.hpp" +#include "sprite/sprite.hpp" +#include "supertux/main.hpp" +#include "supertux/object_factory.hpp" +#include "supertux/sector.hpp" namespace { - const float MIN_INTENSITY = 0.8; - const float ALPHA_SOLID = 0.7; - const float ALPHA_NONSOLID = 0.3; - const float MIN_SOLIDTIME = 1.0; - const float SWITCH_DELAY = 0.1; /**< seconds to wait for stable conditions until switching solidity */ +const float MIN_INTENSITY = 0.8f; +const float ALPHA_SOLID = 0.7f; +const float ALPHA_NONSOLID = 0.3f; +const float MIN_SOLIDTIME = 1.0f; +const float SWITCH_DELAY = 0.1f; /**< seconds to wait for stable conditions until switching solidity */ } -MagicBlock::MagicBlock(const lisp::Lisp& lisp) - : MovingSprite(lisp, "images/objects/magicblock/magicblock.sprite"), - is_solid(false), solid_time(0), switch_delay(0), light(1.0f,1.0f,1.0f) +MagicBlock::MagicBlock(const Reader& lisp) : + MovingSprite(lisp, "images/objects/magicblock/magicblock.sprite"), + is_solid(false), + trigger_red(), + trigger_green(), + trigger_blue(), + solid_time(0), + switch_delay(0), + color(), + light(1.0f,1.0f,1.0f), + center(), + black() { set_group(COLGROUP_STATIC); //get color from lisp std::vector vColor; - lisp.get_vector("color", vColor ); + lisp.get("color", vColor ); color = Color( vColor ); //all alpha to make the sprite still visible color.alpha = ALPHA_SOLID; //set trigger - trigger_red = (color.red == 1.0f ? MIN_INTENSITY : 0); - trigger_green = (color.green == 1.0f ? MIN_INTENSITY : 0); - trigger_blue = (color.blue == 1.0f ? MIN_INTENSITY : 0); + if(color.red == 0 && color.green == 0 && color.blue == 0) { //is it black? + black = true; + trigger_red = MIN_INTENSITY; + trigger_green = MIN_INTENSITY; + trigger_blue = MIN_INTENSITY; + } else { + black = false; + trigger_red = (color.red == 1.0f ? MIN_INTENSITY : 0); + trigger_green = (color.green == 1.0f ? MIN_INTENSITY : 0); + trigger_blue = (color.blue == 1.0f ? MIN_INTENSITY : 0); + } center = get_bbox().get_middle(); } @@ -65,20 +76,26 @@ MagicBlock::MagicBlock(const lisp::Lisp& lisp) void MagicBlock::update(float elapsed_time) { - //Check if this block is on screen. - //Don't update if not because there is no light off screen. + //Check if center of this block is on screen. + //Don't update if not, because there is no light off screen. float screen_left = Sector::current()->camera->get_translation().x; float screen_top = Sector::current()->camera->get_translation().y; float screen_right = screen_left+ SCREEN_WIDTH; float screen_bottom = screen_top + SCREEN_HEIGHT; - if((get_bbox().p1.x > screen_right ) || ( get_bbox().p1.y > screen_bottom) || - ( get_bbox().p2.x < screen_left) || ( get_bbox().p2.y < screen_top)) { + if((center.x > screen_right ) || ( center.y > screen_bottom) || + ( center.x < screen_left) || ( center.y < screen_top)) { switch_delay = SWITCH_DELAY; return; } - bool lighting_ok = (light.red >= trigger_red && light.green >= trigger_green - && light.blue >= trigger_blue); + bool lighting_ok; + if(black) { + lighting_ok = (light.red >= trigger_red || light.green >= trigger_green + || light.blue >= trigger_blue); + }else{ + lighting_ok = (light.red >= trigger_red && light.green >= trigger_green + && light.blue >= trigger_blue); + } // overrule lighting_ok if switch_delay has not yet passed if (lighting_ok == is_solid) { @@ -130,14 +147,18 @@ MagicBlock::draw(DrawingContext& context){ context.draw_filled_rect( get_bbox(), color, layer); } +bool +MagicBlock::collides(GameObject& /*other*/, const CollisionHit& /*hit*/) +{ + return is_solid; +} + HitResponse MagicBlock::collision(GameObject& /*other*/, const CollisionHit& /*hit*/) { - if(is_solid) { - return SOLID; - } else { - return PASSTHROUGH; - } + return SOLID; } IMPLEMENT_FACTORY(MagicBlock, "magicblock"); + +/* EOF */