- context.set_translation(Vector(0,0));
-
- std::vector<Particle*>::iterator i;
- for(i = particles.begin(); i != particles.end(); ++i) {
- Particle* particle = *i;
-
- // remap x,y coordinates onto screencoordinates
- Vector pos;
- pos.x = fmodf(particle->pos.x - scrollx, virtual_width);
- if(pos.x < 0) pos.x += virtual_width;
- pos.y = fmodf(particle->pos.y - scrolly, virtual_height);
- if(pos.y < 0) 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);
- }
-
- context.pop_transform();
-}
-
-SnowParticleSystem::SnowParticleSystem()
-{
- 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_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_HEIGHT;
- int snowsize = rand() % 3;
- particle->texture = snowimages[snowsize];
- do {
- particle->speed = snowsize*.2 + (float(rand()%10)*.4);
- } while(particle->speed < 1);
- particle->speed *= 10; // gravity
-
- particles.push_back(particle);
- }
-}
-
-void
-SnowParticleSystem::parse(const lisp::Lisp& reader)
-{
- reader.get("layer", layer);
-}
-
-void
-SnowParticleSystem::write(lisp::Writer& 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)
- delete snowimages[i];
-}
-
-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_HEIGHT) {
- particle->pos.y = fmodf(particle->pos.y , virtual_height);
- particle->pos.x = rand() % int(virtual_width);
- }
- }
-}
-
-//FIXME: Sometimes both ghosts have the same image
-// Ghosts don't change their movement pattern - not random
-GhostParticleSystem::GhostParticleSystem()
-{
- ghosts[0] = new Surface("images/objects/particles/ghost0.png", true);
- ghosts[1] = new Surface("images/objects/particles/ghost1.png", true);