From: Marek Moeckel Date: Wed, 16 Mar 2005 11:35:16 +0000 (+0000) Subject: added rain particle system, check it out in verticalforest.stl X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=cf585f019ce5aacf92e252a2f2c60c47255bea52;p=supertux.git added rain particle system, check it out in verticalforest.stl SVN-Revision: 2292 --- diff --git a/data/images/shared/rain0.png b/data/images/shared/rain0.png new file mode 100644 index 000000000..4ef221c07 Binary files /dev/null and b/data/images/shared/rain0.png differ diff --git a/data/images/shared/rain1.png b/data/images/shared/rain1.png new file mode 100644 index 000000000..c9c6455d4 Binary files /dev/null and b/data/images/shared/rain1.png differ diff --git a/data/levels/test/verticalforest.stl b/data/levels/test/verticalforest.stl index 34bdfd31b..c53c858dc 100644 --- a/data/levels/test/verticalforest.stl +++ b/data/levels/test/verticalforest.stl @@ -17,7 +17,7 @@ (bkgd_blue_bottom 255) (time 500) (gravity 10) - (particle_system "") + (particle_system "rain") (theme "antarctica") (interactive-tm 0 0 0 0 0 212 0 0 0 0 0 0 0 0 0 0 133 0 0 0 0 0 0 0 0 0 0 212 212 212 diff --git a/data/levels/world1/level19.stl b/data/levels/world1/level19.stl index 577af4565..eba5cd101 100644 --- a/data/levels/world1/level19.stl +++ b/data/levels/world1/level19.stl @@ -8,7 +8,7 @@ (start_pos_x 100) (start_pos_y 170) (background "cave2.jpg") - (music "cave_remastered.ogg") + (music "cave.mod") (bkgd_red_top 150) (bkgd_green_top 150) (bkgd_blue_top 150) diff --git a/src/object/particlesystem.cpp b/src/object/particlesystem.cpp index 4c24b1fc6..232d2cc93 100644 --- a/src/object/particlesystem.cpp +++ b/src/object/particlesystem.cpp @@ -130,6 +130,64 @@ void SnowParticleSystem::action(float elapsed_time) } } +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; ipos.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::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); diff --git a/src/object/particlesystem.h b/src/object/particlesystem.h index 2aae2959d..b2a0c71f2 100644 --- a/src/object/particlesystem.h +++ b/src/object/particlesystem.h @@ -98,6 +98,30 @@ private: 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: diff --git a/src/sector.cpp b/src/sector.cpp index 96f7f3491..655eb22a3 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -100,6 +100,10 @@ Sector::parse_object(const std::string& name, const lisp::Lisp& reader) 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); @@ -206,6 +210,8 @@ Sector::parse_old_format(const lisp::Lisp& 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);