}
}
+RainParticleSystem::RainParticleSystem()
+{
+ rainimages[0] = new Surface(datadir+"/images/shared/rain0.png", true);
+ rainimages[1] = new Surface(datadir+"/images/shared/rain1.png", true);
+
+ virtual_width = screen->w * 2;
+
+ // create some random snowflakes
+ size_t raindropcount = size_t(virtual_width/8.0);
+ for(size_t i=0; i<raindropcount; ++i) {
+ RainParticle* particle = new RainParticle;
+ particle->pos.x = rand() % int(virtual_width);
+ particle->pos.y = rand() % screen->h;
+ int rainsize = rand() % 2;
+ particle->texture = rainimages[rainsize];
+ do {
+ particle->speed = (rainsize+1)*45 + (float(rand()%10)*.4);
+ } while(particle->speed < 1);
+ particle->speed *= 10; // gravity
+
+ particles.push_back(particle);
+ }
+}
+
+void
+RainParticleSystem::parse(const lisp::Lisp& reader)
+{
+ reader.get("layer", layer);
+}
+
+void
+RainParticleSystem::write(lisp::Writer& writer)
+{
+ writer.start_list("particles-rain");
+ writer.write_int("layer", layer);
+ writer.end_list("particles-rain");
+}
+
+RainParticleSystem::~RainParticleSystem()
+{
+ for(int i=0;i<2;++i)
+ delete rainimages[i];
+}
+
+void RainParticleSystem::action(float elapsed_time)
+{
+ std::vector<Particle*>::iterator i;
+ for(i = particles.begin(); i != particles.end(); ++i) {
+ RainParticle* particle = (RainParticle*) *i;
+ particle->pos.y += particle->speed * elapsed_time;
+ particle->pos.x -= particle->speed * elapsed_time;
+ if(particle->pos.y > screen->h) {
+ particle->pos.y = fmodf(particle->pos.y , virtual_height);
+ particle->pos.x = rand() % int(virtual_width);
+ }
+ }
+}
+
CloudParticleSystem::CloudParticleSystem()
{
cloudimage = new Surface(datadir + "/images/shared/cloud.png", true);
Surface* snowimages[3];
};
+class RainParticleSystem : public ParticleSystem, public Serializable
+{
+public:
+ RainParticleSystem();
+ virtual ~RainParticleSystem();
+
+ void parse(const lisp::Lisp& lisp);
+ void write(lisp::Writer& writer);
+
+ virtual void action(float elapsed_time);
+
+ std::string type() const
+ { return "RainParticleSystem"; }
+
+private:
+ class RainParticle : public Particle
+ {
+ public:
+ float speed;
+ };
+
+ Surface* rainimages[2];
+};
+
class CloudParticleSystem : public ParticleSystem, public Serializable
{
public:
SnowParticleSystem* partsys = new SnowParticleSystem();
partsys->parse(reader);
return partsys;
+ } else if(name == "particles-rain") {
+ RainParticleSystem* partsys = new RainParticleSystem();
+ partsys->parse(reader);
+ return partsys;
} else if(name == "particles-clouds") {
CloudParticleSystem* partsys = new CloudParticleSystem();
partsys->parse(reader);
add_object(new CloudParticleSystem());
else if(particlesystem == "snow")
add_object(new SnowParticleSystem());
+ else if(particlesystem == "rain")
+ add_object(new RainParticleSystem());
Vector startpos(100, 170);
reader.get("start_pos_x", startpos.x);