sprite->set_color(color);
sprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
+ sprite->set_angle(90); // FIXME: color won't get applied for angle=0
sprite->draw(context, position, 0);
context.pop_target();
void update(float elapsed_time);
void draw(DrawingContext& context);
-private:
+protected:
Vector position;
Color color;
Sprite* sprite;
--- /dev/null
+// $Id$
+//
+// SuperTux - Pulsing Light
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+// 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 distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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>
+
+#include "pulsing_light.hpp"
+#include "video/color.hpp"
+#include <math.h>
+#include "random_generator.hpp"
+
+PulsingLight::PulsingLight(const Vector& center, float cycle_len, float min_alpha, float max_alpha, const Color& color)
+ : Light(center, color), min_alpha(min_alpha), max_alpha(max_alpha), cycle_len(cycle_len), t(0)
+{
+ assert(cycle_len > 0);
+
+ // start with random phase offset
+ t = systemRandom.randf(0.0, cycle_len);
+}
+
+PulsingLight::~PulsingLight()
+{
+}
+
+void
+PulsingLight::update(float elapsed_time)
+{
+ Light::update(elapsed_time);
+
+ t += elapsed_time;
+ if (t > cycle_len) t -= cycle_len;
+}
+
+void
+PulsingLight::draw(DrawingContext& context)
+{
+ Color old_color = color;
+
+ color.alpha *= min_alpha + ((max_alpha - min_alpha) * cos(2 * M_PI * t / cycle_len));
+ Light::draw(context);
+
+ color = old_color;
+}
+
--- /dev/null
+// $Id$
+//
+// SuperTux - Pulsing Light
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
+//
+// 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 distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// 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.
+
+#ifndef __PULSING_LIGHT_HPP__
+#define __PULSING_LIGHT_HPP__
+
+#include "light.hpp"
+#include "game_object.hpp"
+#include "lisp/lisp.hpp"
+#include "math/vector.hpp"
+#include "video/color.hpp"
+
+class Sprite;
+
+/**
+ * Light source that changes alpha value to give the impression of a pulsating light
+ */
+class PulsingLight : public Light
+{
+public:
+ PulsingLight(const Vector& center, float cycle_len = 5.0, float min_alpha = 0.0, float max_alpha = 1.0, const Color& color = Color(1.0, 1.0, 1.0, 1.0));
+ virtual ~PulsingLight();
+
+ void update(float elapsed_time);
+ void draw(DrawingContext& context);
+
+protected:
+ float min_alpha; /**< minimum alpha */
+ float max_alpha; /**< maximum alpha */
+ float cycle_len; /**< length in seconds of one cycle */
+
+ float t; /**< local time in seconds */
+};
+
+#endif
#include "object/block.hpp"
#include "object/invisible_block.hpp"
#include "object/light.hpp"
+#include "object/pulsing_light.hpp"
#include "object/bullet.hpp"
#include "object/text_object.hpp"
#include "object/portable.hpp"
// torch
if (tile->getID() == 1517) {
- add_object(new Light(center, Color(1.0, 0.6, 0.3, 1.0)));
+ float pseudo_rnd = (float)((int)pos.x % 10) / 10;
+ add_object(new PulsingLight(center, 1.0 + pseudo_rnd, 0.9, 1.0, Color(1.0, 1.0, 0.6, 1.0)));
}
// lava or lavaflow
if ((tile->getID() == 173) || (tile->getID() == 1700) || (tile->getID() == 1705) || (tile->getID() == 1706)) {
if (((tm->get_tile(x-1, y)->getID() != tm->get_tile(x,y)->getID())
&& (tm->get_tile(x, y-1)->getID() != tm->get_tile(x,y)->getID()))
|| ((x % 3 == 0) && (y % 3 == 0))) {
- add_object(new Light(center, Color(1.0, 0.6, 0.6, 1.0)));
+ float pseudo_rnd = (float)((int)pos.x % 10) / 10;
+ add_object(new PulsingLight(center, 1.0 + pseudo_rnd, 0.8, 1.0, Color(1.0, 0.3, 0.0, 1.0)));
}
}