1129097281766f7a6dbf423ca26d3f0bd67fa7b7
[supertux.git] / src / object / fireworks.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 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
19 //  02111-1307, USA.
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
31 Fireworks::Fireworks()
32 {
33   timer.start(.2);
34 }
35
36 Fireworks::~Fireworks()
37 {
38 }
39
40 void
41 Fireworks::update(float )
42 {
43     if(timer.check()) {
44         Sector* sector = Sector::current();
45         Vector pos = sector->camera->get_translation();
46         pos += Vector(SCREEN_WIDTH * ((float) rand() / RAND_MAX),
47                       SCREEN_HEIGHT/2 * ((float) rand() / RAND_MAX));
48
49         float red = static_cast<float>(rand() % 255) / 255.0;
50         float green = static_cast<float>(rand() % ((int) red*255)) / 255.0;
51         sector->add_object(new Particles(pos, 0, 360, Vector(140, 140),
52                 Vector(0, 0), 45, Color(red, green, 0), 3, 1.3,
53                 LAYER_FOREGROUND1+1));
54         sound_manager->play("sounds/fireworks.wav");
55         timer.start(((float) rand() / RAND_MAX) + .5);
56     }
57 }
58
59 void
60 Fireworks::draw(DrawingContext& )
61 {
62 }