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
19#include "sprite/sprite.hpp"
20#include "sprite/sprite_manager.hpp"
21#include "util/reader_mapping.hpp"
22
23Spotlight::Spotlight(const ReaderMapping& mapping) :
24 angle(),
25 center(SpriteManager::current()->create("images/objects/spotlight/spotlight_center.sprite")),
26 base(SpriteManager::current()->create("images/objects/spotlight/spotlight_base.sprite")),
27 lights(SpriteManager::current()->create("images/objects/spotlight/spotlight_lights.sprite")),
28 light(SpriteManager::current()->create("images/objects/spotlight/light.sprite")),
29 lightcone(SpriteManager::current()->create("images/objects/spotlight/lightcone.sprite")),
30 color(1.0f, 1.0f, 1.0f),
31 speed(50.0f),
32 counter_clockwise()
33{
34 m_col.m_group = COLGROUP_DISABLED;
35
36 mapping.get("x", m_col.m_bbox.get_left(), 0.0f);
37 mapping.get("y", m_col.m_bbox.get_top(), 0.0f);
38 m_col.m_bbox.set_size(32, 32);
39
40 mapping.get("angle", angle, 0.0f);
41 mapping.get("speed", speed, 50.0f);
42 mapping.get("counter-clockwise", counter_clockwise, false);
43
44 std::vector<float> vColor;
45 if ( mapping.get( "color", vColor ) ){
46 color = Color( vColor );
47 }
48}
49
50Spotlight::~Spotlight()
51{
52}
53
54ObjectSettings
55Spotlight::get_settings()
56{
57 ObjectSettings result = MovingObject::get_settings();
58
59 result.add_float(_("Angle"), &angle, "angle");
60 result.add_color(_("Color"), &color, "color", Color::WHITE);
61 result.add_float(_("Speed"), &speed, "speed", 50.0f);
62 result.add_bool(_("Counter-clockwise"), &counter_clockwise, "counter-clockwise", false);
63
64 result.reorder({"angle", "color", "x", "y"});
65
66 return result;
67}
68
69void
70Spotlight::update(float dt_sec)
71{
72 if (counter_clockwise)
73 {
74 angle -= dt_sec * speed;
75 }
76 else
77 {
78 angle += dt_sec * speed;
79 }
80}
81
82void
83Spotlight::draw(DrawingContext& context)
84{
85 light->set_color(color);
86 light->set_blend(Blend::ADD);
87 light->set_angle(angle);
88 light->draw(context.light(), m_col.m_bbox.p1(), 0);
89
90 //lightcone->set_angle(angle);
91 //lightcone->draw(context.color(), position, 0);
92
93 lights->set_angle(angle);
94 lights->draw(context.color(), m_col.m_bbox.p1(), 0);
95
96 base->set_angle(angle);
97 base->draw(context.color(), m_col.m_bbox.p1(), 0);
98
99 center->draw(context.color(), m_col.m_bbox.p1(), 0);
100
101 lightcone->set_angle(angle);
102 lightcone->draw(context.color(), m_col.m_bbox.p1(), LAYER_FOREGROUND1 + 10);
103}
104
105HitResponse
106Spotlight::collision(GameObject& other, const CollisionHit& hit_)
107{
108 return FORCE_MOVE;
109}
110
111/* EOF */
112