X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fparticlesystem.cpp;h=b82152a13f4a3c8ef55962facfdc5069c184f42c;hb=6e843b1780f62f45b7021bd8c38181aa211588ee;hp=88b728841c9faf91f3b26157468f408beb578b86;hpb=03fe5c560a616e7d38a8b1d5d11bfe4675fa8896;p=supertux.git diff --git a/src/particlesystem.cpp b/src/particlesystem.cpp index 88b728841..b82152a13 100644 --- a/src/particlesystem.cpp +++ b/src/particlesystem.cpp @@ -17,20 +17,23 @@ // 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 #include -#include -#include "globals.h" -#include "world.h" -#include "level.h" -#include "scene.h" -#include "camera.h" +#include + +#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 +65,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 +73,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; @@ -85,14 +88,28 @@ SnowParticleSystem::SnowParticleSystem() int snowsize = rand() % 3; particle->texture = snowimages[snowsize]; do { - particle->speed = snowsize/60.0 + (float(rand()%10)/300.0); - } while(particle->speed < 0.01); - particle->speed *= World::current()->get_level()->gravity; + particle->speed = snowsize*.2 + (float(rand()%10)*.4); + } while(particle->speed < 1); + particle->speed *= 10; // 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 +131,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; @@ -124,12 +141,26 @@ CloudParticleSystem::CloudParticleSystem() particle->pos.x = rand() % int(virtual_width); particle->pos.y = rand() % int(virtual_height); particle->texture = cloudimage; - particle->speed = -float(250 + rand() % 200) / 1000.0; + particle->speed = -float(25 + rand() % 30); particles.push_back(particle); } } +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;