converted player to new object system
[supertux.git] / src / particlesystem.cpp
index b85ac36..8370536 100644 (file)
 //  You should have received a copy of the GNU General Public License
 //  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 "viewport.h"
+#include "display_manager.h"
 
-ParticleSystem::ParticleSystem()
+ParticleSystem::ParticleSystem(DisplayManager& displaymanager)
 {
     virtual_width = screen->w;
     virtual_height = screen->h;
+
+    displaymanager.add_drawable(this, LAYER_BACKGROUND1);
 }
 
 ParticleSystem::~ParticleSystem()
@@ -37,13 +44,16 @@ ParticleSystem::~ParticleSystem()
     }
 }
 
-void ParticleSystem::draw(float scrollx, float scrolly, int layer)
+void ParticleSystem::draw(ViewPort& viewport, int layer)
 {
     std::vector<Particle*>::iterator i;
     for(i = particles.begin(); i != particles.end(); ++i) {
         Particle* particle = *i;
         if(particle->layer != layer)
             continue;
+
+        float scrollx = viewport.get_translation().x;
+        float scrolly = viewport.get_translation().y;
         
         // remap x,y coordinates onto screencoordinates
         float x = fmodf(particle->x - scrollx, virtual_width);
@@ -61,15 +71,16 @@ void ParticleSystem::draw(float scrollx, float scrolly, int layer)
         
         if(x > screen->w) x -= virtual_width;
         if(y > screen->h) y -= virtual_height;
-        texture_draw(particle->texture, x, y);
+        particle->texture->draw(x, y);
     }
 }
 
-SnowParticleSystem::SnowParticleSystem()
+SnowParticleSystem::SnowParticleSystem(DisplayManager& displaymanager)
+  : ParticleSystem(displaymanager)
 {
-    texture_load(&snowimages[0], datadir+"/images/shared/snow0.png", USE_ALPHA);
-    texture_load(&snowimages[1], datadir+"/images/shared/snow1.png", USE_ALPHA);
-    texture_load(&snowimages[2], datadir+"/images/shared/snow2.png", USE_ALPHA);
+    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);
 
     virtual_width = screen->w * 2;
 
@@ -79,13 +90,13 @@ SnowParticleSystem::SnowParticleSystem()
         SnowParticle* particle = new SnowParticle;
         particle->x = rand() % int(virtual_width);
         particle->y = rand() % screen->h;
-        particle->layer = i % 2;
+        particle->layer = LAYER_BACKGROUND1;
         int snowsize = rand() % 3;
-        particle->texture = &snowimages[snowsize];
+        particle->texture = snowimages[snowsize];
         do {
             particle->speed = snowsize/60.0 + (float(rand()%10)/300.0);
         } while(particle->speed < 0.01);
-        particle->speed *= gravity;
+        particle->speed *= World::current()->get_level()->gravity;
 
         particles.push_back(particle);
     }
@@ -93,11 +104,11 @@ SnowParticleSystem::SnowParticleSystem()
 
 SnowParticleSystem::~SnowParticleSystem()
 {
-    for(int i=0;i<3;++i)
-        texture_free(&snowimages[i]);
+  for(int i=0;i<3;++i)
+    delete snowimages[i];
 }
 
-void SnowParticleSystem::simulate(float elapsed_time)
+void SnowParticleSystem::action(float elapsed_time)
 {
     std::vector<Particle*>::iterator i;
     for(i = particles.begin(); i != particles.end(); ++i) {
@@ -110,9 +121,10 @@ void SnowParticleSystem::simulate(float elapsed_time)
     }
 }
 
-CloudParticleSystem::CloudParticleSystem()
+CloudParticleSystem::CloudParticleSystem(DisplayManager& displaymanager)
+  : ParticleSystem(displaymanager)
 {
-    texture_load(&cloudimage, datadir + "/images/shared/cloud.png", USE_ALPHA);
+    cloudimage = new Surface(datadir + "/images/shared/cloud.png", USE_ALPHA);
 
     virtual_width = 2000.0;
 
@@ -121,8 +133,8 @@ CloudParticleSystem::CloudParticleSystem()
         CloudParticle* particle = new CloudParticle;
         particle->x = rand() % int(virtual_width);
         particle->y = rand() % int(virtual_height);
-        particle->layer = 0;
-        particle->texture = &cloudimage;
+        particle->layer = LAYER_BACKGROUND1;
+        particle->texture = cloudimage;
         particle->speed = -float(250 + rand() % 200) / 1000.0;
 
         particles.push_back(particle);
@@ -131,10 +143,10 @@ CloudParticleSystem::CloudParticleSystem()
 
 CloudParticleSystem::~CloudParticleSystem()
 {
-    texture_free(&cloudimage);
+  delete cloudimage;
 }
 
-void CloudParticleSystem::simulate(float elapsed_time)
+void CloudParticleSystem::action(float elapsed_time)
 {
     std::vector<Particle*>::iterator i;
     for(i = particles.begin(); i != particles.end(); ++i) {