1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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/cloud_particle_system.hpp"
18
19#include "math/random.hpp"
20#include "video/surface.hpp"
21
22CloudParticleSystem::CloudParticleSystem() :
23 ParticleSystem(128),
24 cloudimage(Surface::from_file("images/objects/particles/cloud.png"))
25{
26 init();
27}
28
29CloudParticleSystem::CloudParticleSystem(const ReaderMapping& reader) :
30 ParticleSystem(reader, 128),
31 cloudimage(Surface::from_file("images/objects/particles/cloud.png"))
32{
33 init();
34}
35
36CloudParticleSystem::~CloudParticleSystem()
37{
38}
39
40void CloudParticleSystem::init()
41{
42 virtual_width = 2000.0;
43
44 // create some random clouds
45 for (size_t i=0; i<15; ++i) {
46 auto particle = std::make_unique<CloudParticle>();
47 particle->pos.x = graphicsRandom.randf(virtual_width);
48 particle->pos.y = graphicsRandom.randf(virtual_height);
49 particle->texture = cloudimage;
50 particle->speed = -graphicsRandom.randf(25.0, 54.0);
51
52 particles.push_back(std::move(particle));
53 }
54}
55
56void CloudParticleSystem::update(float dt_sec)
57{
58 if (!enabled)
59 return;
60
61 for (auto& particle : particles) {
62 auto cloudParticle = dynamic_cast<CloudParticle*>(particle.get());
63 if (!cloudParticle)
64 continue;
65 cloudParticle->pos.x += cloudParticle->speed * dt_sec;
66 }
67}
68
69/* EOF */
70