c557453f2b2836e0d9c92be5c6a1f3f75c613518
[supertux.git] / src / object / fireworks.cpp
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 "audio/sound_manager.hpp"
18 #include "math/random_generator.hpp"
19 #include "object/camera.hpp"
20 #include "object/fireworks.hpp"
21 #include "object/particles.hpp"
22 #include "supertux/globals.hpp"
23 #include "supertux/sector.hpp"
24 #include "video/drawing_context.hpp"
25
26 Fireworks::Fireworks() :
27   timer()
28 {
29   timer.start(.2f);
30   SoundManager::current()->preload("sounds/fireworks.wav");
31 }
32
33 Fireworks::~Fireworks()
34 {
35 }
36
37 void
38 Fireworks::update(float )
39 {
40   if(timer.check()) {
41     Sector* sector = Sector::current();
42     Vector pos = sector->camera->get_translation();
43     pos += Vector(graphicsRandom.randf(SCREEN_WIDTH),
44                   graphicsRandom.randf(SCREEN_HEIGHT/2));
45
46     float red = graphicsRandom.randf(1.0);
47     float green = graphicsRandom.randf(1.0);
48     //float red = 0.7;
49     //float green = 0.9;
50     (void) red;
51     (void) green;
52     sector->add_object(std::make_shared<Particles>(pos, 0, 360, Vector(140, 140),
53                                                    Vector(0, 0), 45, Color(red, green, 0), 3, 1.3f,
54                                                    LAYER_FOREGROUND1+1));
55     SoundManager::current()->play("sounds/fireworks.wav");
56     timer.start(graphicsRandom.randf(1.0, 1.5));
57   }
58 }
59
60 void
61 Fireworks::draw(DrawingContext& )
62 {
63 }
64
65 /* EOF */