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"
22 Spotlight::Spotlight(const Reader& lisp) :
30 color(1.0f, 1.0f, 1.0f)
32 lisp.get("x", position.x);
33 lisp.get("y", position.y);
35 lisp.get("angle", angle);
37 std::vector<float> vColor;
38 if( lisp.get( "color", vColor ) ){
39 color = Color( vColor );
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");
50 Spotlight::~Spotlight()
55 Spotlight::update(float delta)
57 angle += delta * 50.0f;
61 Spotlight::draw(DrawingContext& context)
63 context.push_target();
64 context.set_target(DrawingContext::LIGHTMAP);
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);
71 //lightcone->set_angle(angle);
72 //lightcone->draw(context, position, 0);
74 context.set_target(DrawingContext::NORMAL);
76 lights->set_angle(angle);
77 lights->draw(context, position, 0);
79 base->set_angle(angle);
80 base->draw(context, position, 0);
82 center->draw(context, position, 0);
84 lightcone->set_angle(angle);
85 lightcone->draw(context, position, LAYER_FOREGROUND1 + 10);
90 IMPLEMENT_FACTORY(Spotlight, "spotlight");