Fix music not properly fading in again
[supertux.git] / src / object / spotlight.cpp
index e15cdf3..2055b0e 100644 (file)
@@ -1,12 +1,10 @@
-//  $Id: light.cpp 3327 2006-04-13 15:02:40Z ravu_al_hemio $
-//
 //  SuperTux
-//  Copyright (C) 2006 Ingo Ruhnke <grumbel@gmx.de>
+//  Copyright (C) 2006 Ingo Ruhnke <grumbel@gmail.com>
 //
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
 //
 //  This program is distributed in the hope that it will be useful,
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  GNU General Public License for more details.
 //
 //  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-#include <config.h>
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include "spotlight.hpp"
+#include "object/spotlight.hpp"
+#include "sprite/sprite.hpp"
 #include "sprite/sprite_manager.hpp"
-#include "resources.hpp"
-#include "video/drawing_context.hpp"
-#include "object_factory.hpp"
-#include "player.hpp"
-#include "sector.hpp"
+#include "supertux/object_factory.hpp"
+#include "util/reader.hpp"
 
-Spotlight::Spotlight(const lisp::Lisp& )
+Spotlight::Spotlight(const Reader& lisp) :
+  position(),
+  angle(0.0f),
+  center(),
+  base(),
+  lights(),
+  light(),
+  lightcone(),
+  color(1.0f, 1.0f, 1.0f)
 {
-  center    = sprite_manager->create("images/objects/spotlight/spotlight_center.sprite");
-  base      = sprite_manager->create("images/objects/spotlight/spotlight_base.sprite");
-  lights    = sprite_manager->create("images/objects/spotlight/spotlight_lights.sprite");
-  lightcone = sprite_manager->create("images/objects/spotlight/lightcone.sprite");
+  lisp.get("x", position.x);
+  lisp.get("y", position.y);
+
+  lisp.get("angle", angle);
+
+  std::vector<float> vColor;
+  if( lisp.get( "color", vColor ) ){
+    color = Color( vColor );
+  }
+
+  center    = SpriteManager::current()->create("images/objects/spotlight/spotlight_center.sprite");
+  base      = SpriteManager::current()->create("images/objects/spotlight/spotlight_base.sprite");
+  lights    = SpriteManager::current()->create("images/objects/spotlight/spotlight_lights.sprite");
+  lightcone = SpriteManager::current()->create("images/objects/spotlight/lightcone.sprite");
+  light     = SpriteManager::current()->create("images/objects/spotlight/light.sprite");
 
-  angle = 0.0f;
 }
 
 Spotlight::~Spotlight()
 {
-  delete center;
-  delete base;
-  delete lights;
-  delete lightcone;
 }
 
 void
@@ -54,28 +61,31 @@ Spotlight::update(float delta)
 void
 Spotlight::draw(DrawingContext& context)
 {
-  context.push_target(); 
+  context.push_target();
   context.set_target(DrawingContext::LIGHTMAP);
-  Vector pos(100, 300);
 
-  lightcone->set_angle(angle);
-  lightcone->draw(context, pos, 0);
+  light->set_color(color);
+  light->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+  light->set_angle(angle);
+  light->draw(context, position, 0);
+
+  //lightcone->set_angle(angle);
+  //lightcone->draw(context, position, 0);
 
-  lightcone->set_angle(angle + 180.0f);
-  lightcone->draw(context, pos, 0);
-  
   context.set_target(DrawingContext::NORMAL);
 
   lights->set_angle(angle);
-  lights->draw(context, pos, 0);
+  lights->draw(context, position, 0);
 
   base->set_angle(angle);
-  base->draw(context, pos, 0);
+  base->draw(context, position, 0);
 
-  center->draw(context, pos, 0);
+  center->draw(context, position, 0);
+
+  lightcone->set_angle(angle);
+  lightcone->draw(context, position, LAYER_FOREGROUND1 + 10);
 
   context.pop_target();
 }
 
-IMPLEMENT_FACTORY(Spotlight, "spotlight");
+/* EOF */