2 // Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "object/ghost_particle_system.hpp"
21 #include "math/random_generator.hpp"
22 #include "supertux/globals.hpp"
23 #include "video/drawing_context.hpp"
25 //FIXME: Sometimes both ghosts have the same image
26 // Ghosts don't change their movement pattern - not random
27 GhostParticleSystem::GhostParticleSystem()
29 ghosts[0] = Surface::create("images/objects/particles/ghost0.png");
30 ghosts[1] = Surface::create("images/objects/particles/ghost1.png");
32 virtual_width = SCREEN_WIDTH * 2;
35 size_t ghostcount = 2;
36 for(size_t i=0; i<ghostcount; ++i) {
37 GhostParticle* particle = new GhostParticle;
38 particle->pos.x = graphicsRandom.randf(virtual_width);
39 particle->pos.y = graphicsRandom.randf(SCREEN_HEIGHT);
40 int size = graphicsRandom.rand(2);
41 particle->texture = ghosts[size];
42 particle->speed = graphicsRandom.randf(std::max(50, (size * 10)), 180 + (size * 10));
43 particles.push_back(particle);
48 GhostParticleSystem::parse(const Reader& reader)
50 z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1);
53 GhostParticleSystem::~GhostParticleSystem()
57 void GhostParticleSystem::update(float elapsed_time)
59 std::vector<Particle*>::iterator i;
60 for(i = particles.begin(); i != particles.end(); ++i) {
61 GhostParticle* particle = (GhostParticle*) *i;
62 particle->pos.y -= particle->speed * elapsed_time;
63 particle->pos.x -= particle->speed * elapsed_time;
64 if(particle->pos.y > SCREEN_HEIGHT) {
65 particle->pos.y = fmodf(particle->pos.y , virtual_height);
66 particle->pos.x = graphicsRandom.rand(static_cast<int>(virtual_width));