00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "object/spotlight.hpp"
00018 #include "sprite/sprite.hpp"
00019 #include "sprite/sprite_manager.hpp"
00020 #include "supertux/object_factory.hpp"
00021 #include "util/reader.hpp"
00022
00023 Spotlight::Spotlight(const Reader& lisp) :
00024 position(),
00025 angle(0.0f),
00026 center(),
00027 base(),
00028 lights(),
00029 light(),
00030 lightcone(),
00031 color(1.0f, 1.0f, 1.0f)
00032 {
00033 lisp.get("x", position.x);
00034 lisp.get("y", position.y);
00035
00036 lisp.get("angle", angle);
00037
00038 std::vector<float> vColor;
00039 if( lisp.get( "color", vColor ) ){
00040 color = Color( vColor );
00041 }
00042
00043 center = sprite_manager->create("images/objects/spotlight/spotlight_center.sprite");
00044 base = sprite_manager->create("images/objects/spotlight/spotlight_base.sprite");
00045 lights = sprite_manager->create("images/objects/spotlight/spotlight_lights.sprite");
00046 lightcone = sprite_manager->create("images/objects/spotlight/lightcone.sprite");
00047 light = sprite_manager->create("images/objects/spotlight/light.sprite");
00048
00049 }
00050
00051 Spotlight::~Spotlight()
00052 {
00053 }
00054
00055 void
00056 Spotlight::update(float delta)
00057 {
00058 angle += delta * 50.0f;
00059 }
00060
00061 void
00062 Spotlight::draw(DrawingContext& context)
00063 {
00064 context.push_target();
00065 context.set_target(DrawingContext::LIGHTMAP);
00066
00067 light->set_color(color);
00068 light->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
00069 light->set_angle(angle);
00070 light->draw(context, position, 0);
00071
00072
00073
00074
00075 context.set_target(DrawingContext::NORMAL);
00076
00077 lights->set_angle(angle);
00078 lights->draw(context, position, 0);
00079
00080 base->set_angle(angle);
00081 base->draw(context, position, 0);
00082
00083 center->draw(context, position, 0);
00084
00085 lightcone->set_angle(angle);
00086 lightcone->draw(context, position, LAYER_FOREGROUND1 + 10);
00087
00088 context.pop_target();
00089 }
00090
00091