- 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) {
- particle->pos.y = fmodf(particle->pos.y , virtual_height);
- particle->pos.x = rand() % int(virtual_width);
- }
+ ghosts[0] = new Surface("images/objects/particles/ghost0.png");
+ ghosts[1] = new Surface("images/objects/particles/ghost1.png");
+
+ virtual_width = SCREEN_WIDTH * 2;
+
+ // create two ghosts
+ size_t ghostcount = 2;
+ for(size_t i=0; i<ghostcount; ++i) {
+ GhostParticle* particle = new GhostParticle;
+ particle->pos.x = systemRandom.randf(virtual_width);
+ particle->pos.y = systemRandom.randf(SCREEN_HEIGHT);
+ int size = systemRandom.rand(2);
+ particle->texture = ghosts[size];
+ particle->speed = systemRandom.randf(std::max(50, (size * 10)), 180 + (size * 10));
+ particles.push_back(particle);
+ }
+}
+
+void
+GhostParticleSystem::parse(const lisp::Lisp& reader)
+{
+ reader.get("z-pos", z_pos);
+}
+
+void
+GhostParticleSystem::write(lisp::Writer& writer)
+{
+ writer.start_list("particles-ghosts");
+ writer.write_int("z-pos", z_pos);
+ writer.end_list("particles-ghosts");
+}
+
+GhostParticleSystem::~GhostParticleSystem()
+{
+ for(int i=0;i<2;++i)
+ delete ghosts[i];
+}
+
+void GhostParticleSystem::update(float elapsed_time)
+{
+ std::vector<Particle*>::iterator i;
+ for(i = particles.begin(); i != particles.end(); ++i) {
+ GhostParticle* particle = (GhostParticle*) *i;
+ particle->pos.y -= particle->speed * elapsed_time;
+ particle->pos.x -= particle->speed * elapsed_time;
+ if(particle->pos.y > SCREEN_HEIGHT) {
+ particle->pos.y = fmodf(particle->pos.y , virtual_height);
+ particle->pos.x = systemRandom.rand(static_cast<int>(virtual_width));