src/object/pulsing_light.cpp

Go to the documentation of this file.
00001 //  SuperTux - Pulsing Light
00002 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "object/pulsing_light.hpp"
00018 #include <math.h>
00019 
00020 #include "math/random_generator.hpp"
00021 
00022 PulsingLight::PulsingLight(const Vector& center, float cycle_len, float min_alpha, float max_alpha, const Color& color) :
00023   Light(center, color),
00024   min_alpha(min_alpha),
00025   max_alpha(max_alpha), 
00026   cycle_len(cycle_len), 
00027   t(0)
00028 {
00029   assert(cycle_len > 0);
00030 
00031   // start with random phase offset
00032   t = gameRandom.randf(0.0, cycle_len);
00033 }
00034 
00035 PulsingLight::~PulsingLight()
00036 {
00037 }
00038 
00039 void
00040 PulsingLight::update(float elapsed_time)
00041 {
00042   Light::update(elapsed_time);
00043 
00044   t += elapsed_time;
00045   if (t > cycle_len) t -= cycle_len;
00046 }
00047 
00048 void
00049 PulsingLight::draw(DrawingContext& context)
00050 {
00051   Color old_color = color;
00052 
00053   color.alpha *= min_alpha + ((max_alpha - min_alpha) * cos(2 * M_PI * t / cycle_len));
00054   Light::draw(context);
00055 
00056   color = old_color;
00057 }
00058 
00059 /* EOF */

Generated on Mon Jun 9 03:38:20 2014 for SuperTux by  doxygen 1.5.1