36b7bef9f194b4f2cdea6bcd8d5cb0969124923d
[supertux.git] / src / object / spotlight.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.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 "object/spotlight.hpp"
18 #include "sprite/sprite.hpp"
19 #include "sprite/sprite_manager.hpp"
20 #include "supertux/object_factory.hpp"
21
22 Spotlight::Spotlight(const Reader& lisp) :
23   position(),
24   angle(0.0f),
25   center(),
26   base(),
27   lights(),
28   light(),
29   lightcone(),
30   color(1.0f, 1.0f, 1.0f)
31 {
32   lisp.get("x", position.x);
33   lisp.get("y", position.y);
34
35   lisp.get("angle", angle);
36
37   std::vector<float> vColor;
38   if( lisp.get( "color", vColor ) ){
39     color = Color( vColor );
40   }
41
42   center    = sprite_manager->create("images/objects/spotlight/spotlight_center.sprite");
43   base      = sprite_manager->create("images/objects/spotlight/spotlight_base.sprite");
44   lights    = sprite_manager->create("images/objects/spotlight/spotlight_lights.sprite");
45   lightcone = sprite_manager->create("images/objects/spotlight/lightcone.sprite");
46   light     = sprite_manager->create("images/objects/spotlight/light.sprite");
47
48 }
49
50 Spotlight::~Spotlight()
51 {
52 }
53
54 void
55 Spotlight::update(float delta)
56 {
57   angle += delta * 50.0f;
58 }
59
60 void
61 Spotlight::draw(DrawingContext& context)
62 {
63   context.push_target();
64   context.set_target(DrawingContext::LIGHTMAP);
65
66   light->set_color(color);
67   light->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
68   light->set_angle(angle);
69   light->draw(context, position, 0);
70
71   //lightcone->set_angle(angle);
72   //lightcone->draw(context, position, 0);
73
74   context.set_target(DrawingContext::NORMAL);
75
76   lights->set_angle(angle);
77   lights->draw(context, position, 0);
78
79   base->set_angle(angle);
80   base->draw(context, position, 0);
81
82   center->draw(context, position, 0);
83
84   lightcone->set_angle(angle);
85   lightcone->draw(context, position, LAYER_FOREGROUND1 + 10);
86
87   context.pop_target();
88 }
89
90 IMPLEMENT_FACTORY(Spotlight, "spotlight");
91
92 /* EOF */