#include <iostream>
#include <cmath>
-#include "particlesystem.h"
-#include "video/drawing_context.h"
-#include "lisp/parser.h"
-#include "lisp/lisp.h"
-#include "lisp/writer.h"
-#include "resources.h"
-#include "main.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()
{
SnowParticleSystem::SnowParticleSystem()
{
- snowimages[0] = new Surface(datadir+"/images/objects/particles/snow0.png", true);
- snowimages[1] = new Surface(datadir+"/images/objects/particles/snow1.png", true);
- snowimages[2] = new Surface(datadir+"/images/objects/particles/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_WIDTH * 2;
}
}
-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/objects/particles/rain0.png", true);
- rainimages[1] = new Surface(datadir+"/images/objects/particles/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_WIDTH * 2;
- // create some random raindrops
- 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_HEIGHT;
- int rainsize = rand() % 2;
- particle->texture = rainimages[rainsize];
+ 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::update(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_HEIGHT) {
particle->pos.y = fmodf(particle->pos.y , virtual_height);
CloudParticleSystem::CloudParticleSystem()
{
- cloudimage = new Surface(datadir + "/images/objects/particles/cloud.png", true);
+ cloudimage = new Surface("images/objects/particles/cloud.png", true);
virtual_width = 2000.0;