PulsingLight Class Reference

Light source that changes alpha value to give the impression of a pulsating light. More...

#include <pulsing_light.hpp>

Inherits Light.

List of all members.

Public Member Functions

 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)
 This function is called once per frame and allows the object to update it's state.
void draw (DrawingContext &context)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.

Protected Attributes

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


Detailed Description

Light source that changes alpha value to give the impression of a pulsating light.

Definition at line 27 of file pulsing_light.hpp.


Constructor & Destructor Documentation

PulsingLight::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) 
)

Definition at line 22 of file pulsing_light.cpp.

References gameRandom, RandomGenerator::randf(), and t.

00022                                                                                                                       :
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 }

PulsingLight::~PulsingLight (  )  [virtual]

Definition at line 35 of file pulsing_light.cpp.

00036 {
00037 }


Member Function Documentation

void PulsingLight::update ( float  elapsed_time  )  [virtual]

This function is called once per frame and allows the object to update it's state.

The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)

Reimplemented from Light.

Definition at line 40 of file pulsing_light.cpp.

References cycle_len, t, and Light::update().

00041 {
00042   Light::update(elapsed_time);
00043 
00044   t += elapsed_time;
00045   if (t > cycle_len) t -= cycle_len;
00046 }

void PulsingLight::draw ( DrawingContext context  )  [virtual]

The GameObject should draw itself onto the provided DrawingContext if this function is called.

Reimplemented from Light.

Definition at line 49 of file pulsing_light.cpp.

References Color::alpha, Light::color, cycle_len, Light::draw(), max_alpha, min_alpha, and t.

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 }


Member Data Documentation

float PulsingLight::min_alpha [protected]

minimum alpha

Definition at line 37 of file pulsing_light.hpp.

Referenced by draw().

float PulsingLight::max_alpha [protected]

maximum alpha

Definition at line 38 of file pulsing_light.hpp.

Referenced by draw().

float PulsingLight::cycle_len [protected]

length in seconds of one cycle

Definition at line 39 of file pulsing_light.hpp.

Referenced by draw(), and update().

float PulsingLight::t [protected]

local time in seconds

Definition at line 41 of file pulsing_light.hpp.

Referenced by draw(), PulsingLight(), and update().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:34 2014 for SuperTux by  doxygen 1.5.1