3 // SuperTux - Pulsing Light
4 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "pulsing_light.hpp"
23 #include "video/color.hpp"
25 #include "random_generator.hpp"
27 PulsingLight::PulsingLight(const Vector& center, float cycle_len, float min_alpha, float max_alpha, const Color& color)
28 : Light(center, color), min_alpha(min_alpha), max_alpha(max_alpha), cycle_len(cycle_len), t(0)
30 assert(cycle_len > 0);
32 // start with random phase offset
33 t = systemRandom.randf(0.0, cycle_len);
36 PulsingLight::~PulsingLight()
41 PulsingLight::update(float elapsed_time)
43 Light::update(elapsed_time);
46 if (t > cycle_len) t -= cycle_len;
50 PulsingLight::draw(DrawingContext& context)
52 Color old_color = color;
54 color.alpha *= min_alpha + ((max_alpha - min_alpha) * cos(2 * M_PI * t / cycle_len));