src/object/spotlight.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
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   //lightcone->set_angle(angle);
00073   //lightcone->draw(context, position, 0);
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 /* EOF */

Generated on Mon Jun 9 03:38:20 2014 for SuperTux by  doxygen 1.5.1