6a29688d651161e82a8086583fec21af127cb618
[supertux.git] / src / object / spotlight.cpp
1 //  $Id: light.cpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.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 "spotlight.hpp"
23 #include "sprite/sprite_manager.hpp"
24 #include "resources.hpp"
25 #include "video/drawing_context.hpp"
26 #include "object_factory.hpp"
27 #include "player.hpp"
28 #include "sector.hpp"
29
30 Spotlight::Spotlight(const lisp::Lisp& lisp)
31   : angle(0.0f),
32     color(1.0f, 1.0f, 1.0f)
33 {
34   lisp.get("x", position.x);
35   lisp.get("y", position.y);
36
37   lisp.get("angle", angle);
38
39   lisp.get("red",   color.red);
40   lisp.get("green", color.green);
41   lisp.get("blue",  color.blue);
42   lisp.get("alpha", color.alpha);
43   
44   center    = sprite_manager->create("images/objects/spotlight/spotlight_center.sprite");
45   base      = sprite_manager->create("images/objects/spotlight/spotlight_base.sprite");
46   lights    = sprite_manager->create("images/objects/spotlight/spotlight_lights.sprite");
47   lightcone = sprite_manager->create("images/objects/spotlight/lightcone.sprite");
48   light     = sprite_manager->create("images/objects/spotlight/light.sprite");
49
50
51 }
52
53 Spotlight::~Spotlight()
54 {
55   delete center;
56   delete base;
57   delete lights;
58   delete lightcone;
59   delete light;
60 }
61
62 void
63 Spotlight::update(float delta)
64 {
65   angle += delta * 50.0f;
66 }
67
68 void
69 Spotlight::draw(DrawingContext& context)
70 {
71   context.push_target(); 
72   context.set_target(DrawingContext::LIGHTMAP);
73  
74   light->set_color(color);
75   light->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
76   light->set_angle(angle);
77   light->draw(context, position, 0);
78
79   //lightcone->set_angle(angle);
80   //lightcone->draw(context, position, 0);
81   
82   context.set_target(DrawingContext::NORMAL);
83
84   lights->set_angle(angle);
85   lights->draw(context, position, 0);
86
87   base->set_angle(angle);
88   base->draw(context, position, 0);
89
90   center->draw(context, position, 0);
91
92   lightcone->set_angle(angle);
93   lightcone->draw(context, position, LAYER_FOREGROUND1 + 10);
94
95   context.pop_target();
96 }
97
98 IMPLEMENT_FACTORY(Spotlight, "spotlight");