Split particlesystem_interactive.?pp into separate files
[supertux.git] / src / object / comet_particle_system.cpp
1 //  SuperTux
2 //  Copyright (C) 2009 Ingo Ruhnke <grumbel@gmx.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/comet_particle_system.hpp"
18
19 #include "math/random_generator.hpp"
20 #include "supertux/globals.hpp"
21 #include "video/surface.hpp"
22 #include "util/reader.hpp"
23
24 CometParticleSystem::CometParticleSystem()
25 {
26   cometimages[0] = new Surface("images/creatures/mr_bomb/exploding-left-0.png");
27   cometimages[1] = new Surface("images/creatures/mr_bomb/exploding-left-0.png");
28
29   virtual_width = SCREEN_WIDTH * 2;
30
31   // create some random comets
32   size_t cometcount = 2;
33   for(size_t i=0; i<cometcount; ++i) {
34     CometParticle* particle = new CometParticle;
35     particle->pos.x = systemRandom.rand(int(virtual_width));
36     particle->pos.y = systemRandom.rand(int(virtual_height));
37     int cometsize = systemRandom.rand(2);
38     particle->texture = cometimages[cometsize];
39     do {
40       particle->speed = (cometsize+1)*30 + systemRandom.randf(3.6);
41     } while(particle->speed < 1);
42     particle->speed *= 10; // gravity
43
44     particles.push_back(particle);
45   }
46 }
47
48 void
49 CometParticleSystem::parse(const Reader& reader)
50 {
51   reader.get("z-pos", z_pos);
52 }
53
54 CometParticleSystem::~CometParticleSystem()
55 {
56   for(int i=0;i<2;++i)
57     delete cometimages[i];
58 }
59
60 void CometParticleSystem::update(float elapsed_time)
61 {
62   (void) elapsed_time;
63 #if 0
64   std::vector<Particle*>::iterator i;
65   for(
66     i = particles.begin(); i != particles.end(); ++i) {
67     CometParticle* particle = (CometParticle*) *i;
68     float movement = particle->speed * elapsed_time;
69     float abs_x = Sector::current()->camera->get_translation().x;
70     float abs_y = Sector::current()->camera->get_translation().y;
71     particle->pos.y += movement;
72     particle->pos.x -= movement;
73     int col = collision(particle, Vector(-movement, movement));
74     if ((particle->pos.y > SCREEN_HEIGHT + abs_y) || (col >= 0)) {
75       if ((particle->pos.y <= SCREEN_HEIGHT + abs_y) && (col >= 1)) {
76         Sector::current()->add_object(new Bomb(particle->pos, LEFT));
77       }
78       int new_x = systemRandom.rand(int(virtual_width)) + int(abs_x);
79       int new_y = 0;
80       //FIXME: Don't move particles over solid tiles
81       particle->pos.x = new_x;
82       particle->pos.y = new_y;
83     }
84   }
85 #endif
86 }
87
88 /* EOF */