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