Committing RandomGenerator patch from Allen King, with a few small changes
[supertux.git] / src / object / fireworks.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #include <config.h>
21
22 #include "fireworks.hpp"
23 #include "resources.hpp"
24 #include "sector.hpp"
25 #include "camera.hpp"
26 #include "particles.hpp"
27 #include "main.hpp"
28 #include "video/drawing_context.hpp"
29 #include "audio/sound_manager.hpp"
30 #include "random_generator.hpp"
31
32 Fireworks::Fireworks()
33 {
34   timer.start(.2);
35 }
36
37 Fireworks::~Fireworks()
38 {
39 }
40
41 void
42 Fireworks::update(float )
43 {
44     if(timer.check()) {
45         Sector* sector = Sector::current();
46         Vector pos = sector->camera->get_translation();
47         pos += Vector(systemRandom.randf(SCREEN_WIDTH),
48                       systemRandom.randf(SCREEN_HEIGHT/2));
49
50         float red = systemRandom.randf(1.0);
51         float green = systemRandom.randf(1.0);
52         //float red = 0.7;
53         //float green = 0.9;
54         (void) red;
55         (void) green;
56         sector->add_object(new Particles(pos, 0, 360, Vector(140, 140),
57                 Vector(0, 0), 45, Color(red, green, 0), 3, 1.3,
58                 LAYER_FOREGROUND1+1));
59         sound_manager->play("sounds/fireworks.wav");
60         timer.start(systemRandom.randf(1.0, 1.5));
61     }
62 }
63
64 void
65 Fireworks::draw(DrawingContext& )
66 {
67 }