RainParticleSystem Class Reference

#include <rain_particle_system.hpp>

Inherits ParticleSystem_Interactive.

List of all members.

Public Member Functions

 RainParticleSystem ()
virtual ~RainParticleSystem ()
void parse (const Reader &lisp)
virtual void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
std::string type () const

Private Member Functions

 RainParticleSystem (const RainParticleSystem &)
RainParticleSystemoperator= (const RainParticleSystem &)

Private Attributes

SurfacePtr rainimages [2]

Classes

class  RainParticle


Detailed Description

Definition at line 25 of file rain_particle_system.hpp.


Constructor & Destructor Documentation

RainParticleSystem::RainParticleSystem (  ) 

Definition at line 24 of file rain_particle_system.cpp.

References Surface::create(), graphicsRandom, ParticleSystem_Interactive::particles, rainimages, RandomGenerator::rand(), RandomGenerator::randf(), SCREEN_WIDTH, ParticleSystem_Interactive::virtual_height, and ParticleSystem_Interactive::virtual_width.

00025 {
00026   rainimages[0] = Surface::create("images/objects/particles/rain0.png");
00027   rainimages[1] = Surface::create("images/objects/particles/rain1.png");
00028 
00029   virtual_width = SCREEN_WIDTH * 2;
00030 
00031   // create some random raindrops
00032   size_t raindropcount = size_t(virtual_width/6.0);
00033   for(size_t i=0; i<raindropcount; ++i) {
00034     RainParticle* particle = new RainParticle;
00035     particle->pos.x = graphicsRandom.rand(int(virtual_width));
00036     particle->pos.y = graphicsRandom.rand(int(virtual_height));
00037     int rainsize = graphicsRandom.rand(2);
00038     particle->texture = rainimages[rainsize];
00039     do {
00040       particle->speed = (rainsize+1)*45 + graphicsRandom.randf(3.6);
00041     } while(particle->speed < 1);
00042     particle->speed *= 10; // gravity
00043 
00044     particles.push_back(particle);
00045   }
00046 }

RainParticleSystem::~RainParticleSystem (  )  [virtual]

Definition at line 54 of file rain_particle_system.cpp.

00055 {
00056 }

RainParticleSystem::RainParticleSystem ( const RainParticleSystem  )  [private]


Member Function Documentation

void RainParticleSystem::parse ( const Reader lisp  ) 

Definition at line 49 of file rain_particle_system.cpp.

References LAYER_BACKGROUND1, reader_get_layer(), and ParticleSystem_Interactive::z_pos.

Referenced by Sector::parse_object().

00050 {
00051   z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1);
00052 }

void RainParticleSystem::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)

Implements GameObject.

Definition at line 58 of file rain_particle_system.cpp.

References Sector::add_object(), Sector::camera, ParticleSystem_Interactive::collision(), Sector::current(), Camera::get_translation(), graphicsRandom, ParticleSystem_Interactive::particles, RandomGenerator::rand(), SCREEN_HEIGHT, ParticleSystem_Interactive::virtual_width, Vector::x, and Vector::y.

00059 {
00060   std::vector<Particle*>::iterator i;
00061   for(
00062     i = particles.begin(); i != particles.end(); ++i) {
00063     RainParticle* particle = (RainParticle*) *i;
00064     float movement = particle->speed * elapsed_time;
00065     float abs_x = Sector::current()->camera->get_translation().x;
00066     float abs_y = Sector::current()->camera->get_translation().y;
00067     particle->pos.y += movement;
00068     particle->pos.x -= movement;
00069     int col = collision(particle, Vector(-movement, movement));
00070     if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) {
00071       //Create rainsplash
00072       if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)){
00073         bool vertical = (col == 2);
00074         int splash_x, splash_y;
00075         if (!vertical) { //check if collision happened from above
00076           splash_x = int(particle->pos.x);
00077           splash_y = int(particle->pos.y) - (int(particle->pos.y) % 32) + 32;
00078           Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical));
00079         }
00080         // Uncomment the following to display vertical splashes, too
00081         /* else {
00082            splash_x = int(particle->pos.x) - (int(particle->pos.x) % 32) + 32;
00083            splash_y = int(particle->pos.y);
00084            Sector::current()->add_object(new RainSplash(Vector(splash_x, splash_y),vertical));
00085            } */
00086       }
00087       int new_x = graphicsRandom.rand(int(virtual_width)) + int(abs_x);
00088       int new_y = 0;
00089       //FIXME: Don't move particles over solid tiles
00090       particle->pos.x = new_x;
00091       particle->pos.y = new_y;
00092     }
00093   }
00094 }

std::string RainParticleSystem::type (  )  const [inline]

Definition at line 35 of file rain_particle_system.hpp.

00036   { return "RainParticleSystem"; }

RainParticleSystem& RainParticleSystem::operator= ( const RainParticleSystem  )  [private]


Member Data Documentation

SurfacePtr RainParticleSystem::rainimages[2] [private]

Definition at line 49 of file rain_particle_system.hpp.

Referenced by RainParticleSystem().


The documentation for this class was generated from the following files:
Generated on Mon Apr 21 03:38:27 2014 for SuperTux by  doxygen 1.5.1