Fix patch application
[supertux.git] / src / object / ghost_particle_system.cpp
1 //  SuperTux
2 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmail.com>
3 //
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.
8 //
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.
13 //
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/>.
16
17 #include "object/ghost_particle_system.hpp"
18
19 #include <math.h>
20
21 #include "math/random_generator.hpp"
22 #include "supertux/globals.hpp"
23 #include "video/drawing_context.hpp"
24
25 //FIXME: Sometimes both ghosts have the same image
26 //       Ghosts don't change their movement pattern - not random
27 GhostParticleSystem::GhostParticleSystem()
28 {
29   ghosts[0] = Surface::create("images/objects/particles/ghost0.png");
30   ghosts[1] = Surface::create("images/objects/particles/ghost1.png");
31
32   virtual_width = SCREEN_WIDTH * 2;
33
34   // create two ghosts
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);
44   }
45 }
46
47 void
48 GhostParticleSystem::parse(const Reader& reader)
49 {
50   z_pos = reader_get_layer (reader, /* default = */ LAYER_BACKGROUND1);
51 }
52
53 GhostParticleSystem::~GhostParticleSystem()
54 {
55 }
56
57 void GhostParticleSystem::update(float elapsed_time)
58 {
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));
67     }
68   }
69 }
70
71 /* EOF */