more fixes
[supertux.git] / src / particlesystem.cpp
index 88b7288..ea301d8 100644 (file)
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
-#include "particlesystem.h"
 
 #include <iostream>
-#include <math.h>
-#include "globals.h"
-#include "world.h"
-#include "level.h"
-#include "scene.h"
-#include "camera.h"
+#include <cmath>
+
+#include "particlesystem.h"
+#include "app/globals.h"
+#include "utils/lispreader.h"
+#include "utils/lispwriter.h"
+#include "video/drawing_context.h"
 
 ParticleSystem::ParticleSystem()
 {
     virtual_width = screen->w;
     virtual_height = screen->h;
+    layer = LAYER_BACKGROUND1;
 }
 
 ParticleSystem::~ParticleSystem()
@@ -62,7 +63,7 @@ void ParticleSystem::draw(DrawingContext& context)
 
         if(pos.x > screen->w) pos.x -= virtual_width;
         if(pos.y > screen->h) pos.y -= virtual_height;
-        context.draw_surface(particle->texture, pos, LAYER_BACKGROUND1);
+        context.draw_surface(particle->texture, pos, layer);
     }
 
     context.pop_transform();
@@ -70,9 +71,9 @@ void ParticleSystem::draw(DrawingContext& context)
 
 SnowParticleSystem::SnowParticleSystem()
 {
-    snowimages[0] = new Surface(datadir+"/images/shared/snow0.png", USE_ALPHA);
-    snowimages[1] = new Surface(datadir+"/images/shared/snow1.png", USE_ALPHA);
-    snowimages[2] = new Surface(datadir+"/images/shared/snow2.png", USE_ALPHA);
+    snowimages[0] = new Surface(datadir+"/images/shared/snow0.png", true);
+    snowimages[1] = new Surface(datadir+"/images/shared/snow1.png", true);
+    snowimages[2] = new Surface(datadir+"/images/shared/snow2.png", true);
 
     virtual_width = screen->w * 2;
 
@@ -87,12 +88,25 @@ SnowParticleSystem::SnowParticleSystem()
         do {
             particle->speed = snowsize/60.0 + (float(rand()%10)/300.0);
         } while(particle->speed < 0.01);
-        particle->speed *= World::current()->get_level()->gravity;
 
         particles.push_back(particle);
     }
 }
 
+void
+SnowParticleSystem::parse(LispReader& reader)
+{
+  reader.read_int("layer", layer);
+}
+
+void
+SnowParticleSystem::write(LispWriter& writer)
+{
+  writer.start_list("particles-snow");
+  writer.write_int("layer", layer);
+  writer.end_list("particles-snow");
+}
+
 SnowParticleSystem::~SnowParticleSystem()
 {
   for(int i=0;i<3;++i)
@@ -114,7 +128,7 @@ void SnowParticleSystem::action(float elapsed_time)
 
 CloudParticleSystem::CloudParticleSystem()
 {
-    cloudimage = new Surface(datadir + "/images/shared/cloud.png", USE_ALPHA);
+    cloudimage = new Surface(datadir + "/images/shared/cloud.png", true);
 
     virtual_width = 2000.0;
 
@@ -130,6 +144,20 @@ CloudParticleSystem::CloudParticleSystem()
     }
 }
 
+void
+CloudParticleSystem::parse(LispReader& reader)
+{
+  reader.read_int("layer", layer);
+}
+
+void
+CloudParticleSystem::write(LispWriter& writer)
+{
+  writer.start_list("particles-clouds");
+  writer.write_int("layer", layer);
+  writer.end_list("particles-clouds");
+}
+
 CloudParticleSystem::~CloudParticleSystem()
 {
   delete cloudimage;