- added sprite rotation
[supertux.git] / src / object / spotlight.cpp
1 //  $Id: light.cpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 #include <config.h>
21
22 #include "spotlight.hpp"
23 #include "sprite/sprite_manager.hpp"
24 #include "resources.hpp"
25 #include "video/drawing_context.hpp"
26 #include "object_factory.hpp"
27 #include "player.hpp"
28 #include "sector.hpp"
29
30 Spotlight::Spotlight(const lisp::Lisp& )
31 {
32   center    = sprite_manager->create("images/objects/spotlight/spotlight_center.sprite");
33   base      = sprite_manager->create("images/objects/spotlight/spotlight_base.sprite");
34   lights    = sprite_manager->create("images/objects/spotlight/spotlight_lights.sprite");
35   lightcone = sprite_manager->create("images/objects/spotlight/lightcone.sprite");
36
37   angle = 0.0f;
38 }
39
40 Spotlight::~Spotlight()
41 {
42   delete center;
43   delete base;
44   delete lights;
45   delete lightcone;
46 }
47
48 void
49 Spotlight::update(float delta)
50 {
51   angle += delta * 50.0f;
52 }
53
54 void
55 Spotlight::draw(DrawingContext& context)
56 {
57   context.push_target(); 
58   context.set_target(DrawingContext::LIGHTMAP);
59  
60   Vector pos(100, 300);
61
62   lightcone->set_angle(angle);
63   lightcone->draw(context, pos, 0);
64
65   lightcone->set_angle(angle + 180.0f);
66   lightcone->draw(context, pos, 0);
67   
68   context.set_target(DrawingContext::NORMAL);
69
70   lights->set_angle(angle);
71   lights->draw(context, pos, 0);
72
73   base->set_angle(angle);
74   base->draw(context, pos, 0);
75
76   center->draw(context, pos, 0);
77
78   context.pop_target();
79 }
80
81 IMPLEMENT_FACTORY(Spotlight, "spotlight");