From: Christoph Sommer Date: Thu, 10 Aug 2006 22:55:59 +0000 (+0000) Subject: Candle affects lightmap X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=31ddd3003af65d55f51044a8bf82f6ce999f86f5;p=supertux.git Candle affects lightmap SVN-Revision: 4153 --- diff --git a/data/images/objects/candle/candle-light-1.png b/data/images/objects/candle/candle-light-1.png new file mode 100644 index 000000000..a2e8fe84a Binary files /dev/null and b/data/images/objects/candle/candle-light-1.png differ diff --git a/data/images/objects/candle/candle-light-2.png b/data/images/objects/candle/candle-light-2.png new file mode 100644 index 000000000..5510784e2 Binary files /dev/null and b/data/images/objects/candle/candle-light-2.png differ diff --git a/data/levels/test/candle.stl b/data/levels/test/candle.stl index ef4bf5cbb..3b0e30ecd 100644 --- a/data/levels/test/candle.stl +++ b/data/levels/test/candle.stl @@ -4,11 +4,10 @@ (author "Marek") (sector (name "main") + (ambient-light 0.450721 0.3396048 0.3396048) (background - (x 0) - (y 0) - (image "images/background/arctis.jpg") (speed 0.5) + (image "images/background/BlueRock_Forest/blue-top.jpg") ) (tilemap (z-pos -100) @@ -34,6 +33,15 @@ (height 30) (tiles 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) ) + (tilemap + (z-pos -101) + (solid #f) + (name "TileBG") + (speed 1) + (width 30) + (height 30) + (tiles 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1910 1911 1908 1909 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1914 1915 1912 1913 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1902 1903 1900 1901 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905 1906 1907 1904 1905) + ) (camera (mode "normal") ) diff --git a/src/object/candle.cpp b/src/object/candle.cpp index 924bc38a3..98c48c195 100644 --- a/src/object/candle.cpp +++ b/src/object/candle.cpp @@ -25,10 +25,14 @@ #include "sector.hpp" #include "object/sprite_particle.hpp" #include "object_factory.hpp" +#include "random_generator.hpp" Candle::Candle(const lisp::Lisp& lisp) - : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true) + : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true), + candle_light_1("images/objects/candle/candle-light-1.png"), + candle_light_2("images/objects/candle/candle-light-2.png") { + lisp.get("name", name); lisp.get("burning", burning); if (burning) { @@ -36,6 +40,28 @@ Candle::Candle(const lisp::Lisp& lisp) } else { sprite->set_action("off"); } + +} + +void +Candle::draw(DrawingContext& context) +{ + // draw regular sprite + sprite->draw(context, get_pos(), layer); + + // draw on lightmap + if (burning) { + Vector pos = get_pos() + (bbox.get_size() - candle_light_1.get_size()) / 2; + context.push_target(); + context.set_target(DrawingContext::LIGHTMAP); + // draw approx. 1 in 10 frames darker. Makes the candle flicker + if (systemRandom.rand(10) != 0) { + context.draw_surface(&candle_light_1, pos, layer); + } else { + context.draw_surface(&candle_light_2, pos, layer); + } + context.pop_target(); + } } HitResponse diff --git a/src/object/candle.hpp b/src/object/candle.hpp index 6b40b3e03..95d005a40 100644 --- a/src/object/candle.hpp +++ b/src/object/candle.hpp @@ -25,6 +25,7 @@ #include "lisp/lisp.hpp" #include "object/moving_sprite.hpp" #include "script_interface.hpp" +#include "video/surface.hpp" /** * A burning candle: Simple, scriptable level decoration. @@ -34,6 +35,7 @@ class Candle : public MovingSprite, public ScriptInterface public: Candle(const lisp::Lisp& lisp); virtual Candle* clone() const { return new Candle(*this); } + virtual void draw(DrawingContext& context); HitResponse collision(GameObject& other, const CollisionHit& hit); @@ -47,6 +49,8 @@ public: private: bool burning; /**< true if candle is currently lighted */ + Surface candle_light_1; /**< drawn to lightmap */ + Surface candle_light_2; /**< drawn to lightmap (alternative image) */ }; diff --git a/src/video/surface.hpp b/src/video/surface.hpp index 650f93169..d7021815d 100644 --- a/src/video/surface.hpp +++ b/src/video/surface.hpp @@ -21,6 +21,7 @@ #define __SURFACE_HPP__ #include +#include "math/vector.hpp" class Color; class Blend; @@ -81,6 +82,13 @@ public: { return height; } + + /** + * returns a vector containing width and height + */ + Vector get_size() const + { return Vector(get_width(), get_height()); } + }; #endif