2 // Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.de>
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.
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.
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/>.
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"
23 Spotlight::Spotlight(const Reader& lisp) :
31 color(1.0f, 1.0f, 1.0f)
33 lisp.get("x", position.x);
34 lisp.get("y", position.y);
36 lisp.get("angle", angle);
38 std::vector<float> vColor;
39 if( lisp.get( "color", vColor ) ){
40 color = Color( vColor );
43 center = sprite_manager->create("images/objects/spotlight/spotlight_center.sprite");
44 base = sprite_manager->create("images/objects/spotlight/spotlight_base.sprite");
45 lights = sprite_manager->create("images/objects/spotlight/spotlight_lights.sprite");
46 lightcone = sprite_manager->create("images/objects/spotlight/lightcone.sprite");
47 light = sprite_manager->create("images/objects/spotlight/light.sprite");
51 Spotlight::~Spotlight()
56 Spotlight::update(float delta)
58 angle += delta * 50.0f;
62 Spotlight::draw(DrawingContext& context)
64 context.push_target();
65 context.set_target(DrawingContext::LIGHTMAP);
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);
72 //lightcone->set_angle(angle);
73 //lightcone->draw(context, position, 0);
75 context.set_target(DrawingContext::NORMAL);
77 lights->set_angle(angle);
78 lights->draw(context, position, 0);
80 base->set_angle(angle);
81 base->draw(context, position, 0);
83 center->draw(context, position, 0);
85 lightcone->set_angle(angle);
86 lightcone->draw(context, position, LAYER_FOREGROUND1 + 10);