From: Christoph Sommer Date: Sun, 17 Sep 2006 15:02:05 +0000 (+0000) Subject: Automatically added lights are now colored and a bit more dynamic X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=2ecda1af1f01f4a413d44dcf33a6efea32ef66e6;p=supertux.git Automatically added lights are now colored and a bit more dynamic SVN-Revision: 4238 --- diff --git a/data/images/objects/lightmap_light/lightmap_light.png b/data/images/objects/lightmap_light/lightmap_light.png index b8cf5f91b..d0c87a02c 100644 Binary files a/data/images/objects/lightmap_light/lightmap_light.png and b/data/images/objects/lightmap_light/lightmap_light.png differ diff --git a/src/object/light.cpp b/src/object/light.cpp index 1675cf275..f11e1c2d1 100644 --- a/src/object/light.cpp +++ b/src/object/light.cpp @@ -50,6 +50,7 @@ Light::draw(DrawingContext& context) sprite->set_color(color); sprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + sprite->set_angle(90); // FIXME: color won't get applied for angle=0 sprite->draw(context, position, 0); context.pop_target(); diff --git a/src/object/light.hpp b/src/object/light.hpp index f571ea578..b9b625b91 100644 --- a/src/object/light.hpp +++ b/src/object/light.hpp @@ -36,7 +36,7 @@ public: void update(float elapsed_time); void draw(DrawingContext& context); -private: +protected: Vector position; Color color; Sprite* sprite; diff --git a/src/object/pulsing_light.cpp b/src/object/pulsing_light.cpp new file mode 100644 index 000000000..4f3fd9d14 --- /dev/null +++ b/src/object/pulsing_light.cpp @@ -0,0 +1,59 @@ +// $Id$ +// +// SuperTux - Pulsing Light +// Copyright (C) 2006 Christoph Sommer +// +// 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 distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// 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 "pulsing_light.hpp" +#include "video/color.hpp" +#include +#include "random_generator.hpp" + +PulsingLight::PulsingLight(const Vector& center, float cycle_len, float min_alpha, float max_alpha, const Color& color) + : Light(center, color), min_alpha(min_alpha), max_alpha(max_alpha), cycle_len(cycle_len), t(0) +{ + assert(cycle_len > 0); + + // start with random phase offset + t = systemRandom.randf(0.0, cycle_len); +} + +PulsingLight::~PulsingLight() +{ +} + +void +PulsingLight::update(float elapsed_time) +{ + Light::update(elapsed_time); + + t += elapsed_time; + if (t > cycle_len) t -= cycle_len; +} + +void +PulsingLight::draw(DrawingContext& context) +{ + Color old_color = color; + + color.alpha *= min_alpha + ((max_alpha - min_alpha) * cos(2 * M_PI * t / cycle_len)); + Light::draw(context); + + color = old_color; +} + diff --git a/src/object/pulsing_light.hpp b/src/object/pulsing_light.hpp new file mode 100644 index 000000000..f395968b1 --- /dev/null +++ b/src/object/pulsing_light.hpp @@ -0,0 +1,51 @@ +// $Id$ +// +// SuperTux - Pulsing Light +// Copyright (C) 2006 Christoph Sommer +// +// 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 distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// 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. + +#ifndef __PULSING_LIGHT_HPP__ +#define __PULSING_LIGHT_HPP__ + +#include "light.hpp" +#include "game_object.hpp" +#include "lisp/lisp.hpp" +#include "math/vector.hpp" +#include "video/color.hpp" + +class Sprite; + +/** + * Light source that changes alpha value to give the impression of a pulsating light + */ +class PulsingLight : public Light +{ +public: + PulsingLight(const Vector& center, float cycle_len = 5.0, float min_alpha = 0.0, float max_alpha = 1.0, const Color& color = Color(1.0, 1.0, 1.0, 1.0)); + virtual ~PulsingLight(); + + void update(float elapsed_time); + void draw(DrawingContext& context); + +protected: + float min_alpha; /**< minimum alpha */ + float max_alpha; /**< maximum alpha */ + float cycle_len; /**< length in seconds of one cycle */ + + float t; /**< local time in seconds */ +}; + +#endif diff --git a/src/sector.cpp b/src/sector.cpp index fa931d4af..8ff2d8f66 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -56,6 +56,7 @@ #include "object/block.hpp" #include "object/invisible_block.hpp" #include "object/light.hpp" +#include "object/pulsing_light.hpp" #include "object/bullet.hpp" #include "object/text_object.hpp" #include "object/portable.hpp" @@ -392,7 +393,8 @@ Sector::fix_old_tiles() // torch if (tile->getID() == 1517) { - add_object(new Light(center, Color(1.0, 0.6, 0.3, 1.0))); + float pseudo_rnd = (float)((int)pos.x % 10) / 10; + add_object(new PulsingLight(center, 1.0 + pseudo_rnd, 0.9, 1.0, Color(1.0, 1.0, 0.6, 1.0))); } // lava or lavaflow if ((tile->getID() == 173) || (tile->getID() == 1700) || (tile->getID() == 1705) || (tile->getID() == 1706)) { @@ -400,7 +402,8 @@ Sector::fix_old_tiles() if (((tm->get_tile(x-1, y)->getID() != tm->get_tile(x,y)->getID()) && (tm->get_tile(x, y-1)->getID() != tm->get_tile(x,y)->getID())) || ((x % 3 == 0) && (y % 3 == 0))) { - add_object(new Light(center, Color(1.0, 0.6, 0.6, 1.0))); + float pseudo_rnd = (float)((int)pos.x % 10) / 10; + add_object(new PulsingLight(center, 1.0 + pseudo_rnd, 0.8, 1.0, Color(1.0, 0.3, 0.0, 1.0))); } }