18648e025c5a71daf964505b8f4f048be0c00550
[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
21 #include <config.h>
22
23 #include "fireworks.h"
24 #include "resources.h"
25 #include "sector.h"
26 #include "camera.h"
27 #include "gameobjs.h"
28 #include "app/globals.h"
29 #include "video/drawing_context.h"
30 #include "audio/sound_manager.h"
31
32 using namespace SuperTux;
33
34 Fireworks::Fireworks()
35 {
36   timer.start(.2);
37 }
38
39 Fireworks::~Fireworks()
40 {
41 }
42
43 void
44 Fireworks::action(float )
45 {
46     if(timer.check()) {
47         Sector* sector = Sector::current();
48         Vector pos = sector->camera->get_translation();
49         pos += Vector(SCREEN_WIDTH * ((float) rand() / RAND_MAX),
50                       SCREEN_HEIGHT/2 * ((float) rand() / RAND_MAX));
51
52         int red = rand() % 255;
53         int green = rand() % red;
54         sector->add_object(new Particles(pos, 0, 360, Vector(140, 140),
55                 Vector(0, 0), 45, Color(red, green, 0), 3, 1.3,
56                 LAYER_FOREGROUND1+1));
57         sound_manager->play_sound("fireworks");
58         timer.start(((float) rand() / RAND_MAX) + .5);
59     }
60 }
61
62 void
63 Fireworks::draw(DrawingContext& )
64 {
65 }