renamed all .h to .hpp
[supertux.git] / src / object / particlesystem.cpp
index 232d2cc..5edb5a4 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 <config.h>
 
 #include <iostream>
 #include <cmath>
 
-#include "particlesystem.h"
-#include "app/globals.h"
-#include "video/drawing_context.h"
-#include "lisp/parser.h"
-#include "lisp/lisp.h"
-#include "lisp/writer.h"
+#include "particlesystem.hpp"
+#include "video/drawing_context.hpp"
+#include "lisp/parser.hpp"
+#include "lisp/lisp.hpp"
+#include "lisp/writer.hpp"
+#include "resources.hpp"
+#include "main.hpp"
 
 ParticleSystem::ParticleSystem()
 {
-    virtual_width = screen->w;
-    virtual_height = screen->h;
+    virtual_width = SCREEN_WIDTH;
+    virtual_height = SCREEN_HEIGHT;
     layer = LAYER_BACKGROUND1;
 }
 
@@ -64,8 +63,8 @@ void ParticleSystem::draw(DrawingContext& context)
         pos.y = fmodf(particle->pos.y - scrolly, virtual_height);
         if(pos.y < 0) pos.y += virtual_height;
 
-        if(pos.x > screen->w) pos.x -= virtual_width;
-        if(pos.y > screen->h) pos.y -= virtual_height;
+        if(pos.x > SCREEN_WIDTH) pos.x -= virtual_width;
+        if(pos.y > SCREEN_HEIGHT) pos.y -= virtual_height;
         context.draw_surface(particle->texture, pos, layer);
     }
 
@@ -74,18 +73,18 @@ void ParticleSystem::draw(DrawingContext& context)
 
 SnowParticleSystem::SnowParticleSystem()
 {
-    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);
+    snowimages[0] = new Surface("images/objects/particles/snow0.png", true);
+    snowimages[1] = new Surface("images/objects/particles/snow1.png", true);
+    snowimages[2] = new Surface("images/objects/particles/snow2.png", true);
 
-    virtual_width = screen->w * 2;
+    virtual_width = SCREEN_WIDTH * 2;
 
     // create some random snowflakes
     size_t snowflakecount = size_t(virtual_width/10.0);
     for(size_t i=0; i<snowflakecount; ++i) {
         SnowParticle* particle = new SnowParticle;
         particle->pos.x = rand() % int(virtual_width);
-        particle->pos.y = rand() % screen->h;
+        particle->pos.y = rand() % SCREEN_HEIGHT;
         int snowsize = rand() % 3;
         particle->texture = snowimages[snowsize];
         do {
@@ -117,71 +116,72 @@ SnowParticleSystem::~SnowParticleSystem()
     delete snowimages[i];
 }
 
-void SnowParticleSystem::action(float elapsed_time)
+void SnowParticleSystem::update(float elapsed_time)
 {
     std::vector<Particle*>::iterator i;
     for(i = particles.begin(); i != particles.end(); ++i) {
         SnowParticle* particle = (SnowParticle*) *i;
         particle->pos.y += particle->speed * elapsed_time;
-        if(particle->pos.y > screen->h) {
+        if(particle->pos.y > SCREEN_HEIGHT) {
             particle->pos.y = fmodf(particle->pos.y , virtual_height);
             particle->pos.x = rand() % int(virtual_width);
         }
     }
 }
 
-RainParticleSystem::RainParticleSystem()
+//FIXME: Sometimes both ghosts have the same image
+//       Ghosts don't change their movement pattern - not random
+GhostParticleSystem::GhostParticleSystem()
 {
-    rainimages[0] = new Surface(datadir+"/images/shared/rain0.png", true);
-    rainimages[1] = new Surface(datadir+"/images/shared/rain1.png", true);
+    ghosts[0] = new Surface("images/objects/particles/ghost0.png", true);
+    ghosts[1] = new Surface("images/objects/particles/ghost1.png", true);
 
-    virtual_width = screen->w * 2;
+    virtual_width = SCREEN_WIDTH * 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;
+    // create two ghosts
+    size_t ghostcount = 2;
+    for(size_t i=0; i<ghostcount; ++i) {
+        GhostParticle* particle = new GhostParticle;
         particle->pos.x = rand() % int(virtual_width);
-        particle->pos.y = rand() % screen->h;
-        int rainsize = rand() % 2;
-        particle->texture = rainimages[rainsize];
+        particle->pos.y = rand() % SCREEN_HEIGHT;
+        int size = rand() % 2;
+        particle->texture = ghosts[size];
         do {
-            particle->speed = (rainsize+1)*45 + (float(rand()%10)*.4);
+            particle->speed = size*.2 + (float(rand()%10)*.4);
         } while(particle->speed < 1);
-        particle->speed *= 10; // gravity
-
+        particle->speed *= 50;
         particles.push_back(particle);
     }
 }
 
 void
-RainParticleSystem::parse(const lisp::Lisp& reader)
+GhostParticleSystem::parse(const lisp::Lisp& reader)
 {
   reader.get("layer", layer);
 }
 
 void
-RainParticleSystem::write(lisp::Writer& writer)
+GhostParticleSystem::write(lisp::Writer& writer)
 {
-  writer.start_list("particles-rain");
+  writer.start_list("particles-ghosts");
   writer.write_int("layer", layer);
-  writer.end_list("particles-rain");
+  writer.end_list("particles-ghosts");
 }
 
-RainParticleSystem::~RainParticleSystem()
+GhostParticleSystem::~GhostParticleSystem()
 {
   for(int i=0;i<2;++i)
-    delete rainimages[i];
+    delete ghosts[i];
 }
 
-void RainParticleSystem::action(float elapsed_time)
+void GhostParticleSystem::update(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;
+        GhostParticle* particle = (GhostParticle*) *i;
+        particle->pos.y -= particle->speed * elapsed_time;
         particle->pos.x -= particle->speed * elapsed_time;
-        if(particle->pos.y > screen->h) {
+        if(particle->pos.y > SCREEN_HEIGHT) {
             particle->pos.y = fmodf(particle->pos.y , virtual_height);
             particle->pos.x = rand() % int(virtual_width);
         }
@@ -190,7 +190,7 @@ void RainParticleSystem::action(float elapsed_time)
 
 CloudParticleSystem::CloudParticleSystem()
 {
-    cloudimage = new Surface(datadir + "/images/shared/cloud.png", true);
+    cloudimage = new Surface("images/objects/particles/cloud.png", true);
 
     virtual_width = 2000.0;
 
@@ -225,7 +225,7 @@ CloudParticleSystem::~CloudParticleSystem()
   delete cloudimage;
 }
 
-void CloudParticleSystem::action(float elapsed_time)
+void CloudParticleSystem::update(float elapsed_time)
 {
     std::vector<Particle*>::iterator i;
     for(i = particles.begin(); i != particles.end(); ++i) {