added rain particle system, check it out in verticalforest.stl
authorMarek Moeckel <wansti@gmx.de>
Wed, 16 Mar 2005 11:35:16 +0000 (11:35 +0000)
committerMarek Moeckel <wansti@gmx.de>
Wed, 16 Mar 2005 11:35:16 +0000 (11:35 +0000)
SVN-Revision: 2292

data/images/shared/rain0.png [new file with mode: 0644]
data/images/shared/rain1.png [new file with mode: 0644]
data/levels/test/verticalforest.stl
data/levels/world1/level19.stl
src/object/particlesystem.cpp
src/object/particlesystem.h
src/sector.cpp

diff --git a/data/images/shared/rain0.png b/data/images/shared/rain0.png
new file mode 100644 (file)
index 0000000..4ef221c
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 (file)
index 0000000..c9c6455
Binary files /dev/null and b/data/images/shared/rain1.png differ
index 34bdfd3..c53c858 100644 (file)
@@ -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 
index 577af45..eba5cd1 100644 (file)
@@ -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)
index 4c24b1f..232d2cc 100644 (file)
@@ -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; 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);
index 2aae295..b2a0c71 100644 (file)
@@ -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:
index 96f7f34..655eb22 100644 (file)
@@ -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);