#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 "tile.h"
-#include "tilemap.h"
-#include "math/aatriangle.h"
-#include "collision.h"
-#include "collision_hit.h"
-#include "object/camera.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() % int(virtual_height);
- 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::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;
- float movement = particle->speed * elapsed_time;
- particle->pos.y += movement;
- particle->pos.x -= movement;
- if ((particle->pos.y > SCREEN_HEIGHT) || (collision(particle, Vector(-movement, movement)))) {
- particle->pos.y = Sector::current()->camera->get_translation().y;
+ 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 = rand() % int(virtual_width);
}
}
}
-bool
-RainParticleSystem::collision(RainParticle* object, Vector movement)
-{
- TileMap* solids = Sector::current()->solids;
- // calculate rectangle where the object will move
- float x1, x2;
- float y1, y2;
- x1 = object->pos.x;
- x2 = x1 + 32 + movement.x;
- y1 = object->pos.y;
- y2 = y1 + 32 + movement.y;
-
- // test with all tiles in this rectangle
- int starttilex = int(x1-1) / 32;
- int starttiley = int(y1-1) / 32;
- int max_x = int(x2+1);
- int max_y = int(y2+1);
-
- CollisionHit temphit, hit;
- Rect dest = Rect(x1, y1, x2, y2);
- dest.move(movement);
- hit.time = -1; // represents an invalid value
- for(int x = starttilex; x*32 < max_x; ++x) {
- for(int y = starttiley; y*32 < max_y; ++y) {
- const Tile* tile = solids->get_tile(x, y);
- if(!tile)
- continue;
- // skip non-solid tiles
- if(!(tile->getAttributes() & Tile::SOLID))
- continue;
-
- if(tile->getAttributes() & Tile::SLOPE) { // slope tile
- AATriangle triangle;
- Vector p1(x*32, y*32);
- Vector p2((x+1)*32, (y+1)*32);
- triangle = AATriangle(p1, p2, tile->getData());
-
- if(Collision::rectangle_aatriangle(temphit, dest, movement,
- triangle)) {
- if(temphit.time > hit.time)
- hit = temphit;
- }
- } else { // normal rectangular tile
- Rect rect(x*32, y*32, (x+1)*32, (y+1)*32);
- if(Collision::rectangle_rectangle(temphit, dest,
- movement, rect)) {
- if(temphit.time > hit.time)
- hit = temphit;
- }
- }
- }
- }
-
- // did we collide at all?
- if(hit.time < 0)
- return false; else return true;
-}
-
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;