From: Christoph Sommer Date: Wed, 13 Sep 2006 15:13:43 +0000 (+0000) Subject: Changed "Light" GameObject to be a static, unichrome lightsource. / X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=14bdea449bc5bae5aa0d1f9150967f1c86b893a2;p=supertux.git Changed "Light" GameObject to be a static, unichrome lightsource. / Sector adds "Light" objects for special tiles (currently torch and lava) SVN-Revision: 4234 --- diff --git a/data/images/objects/lightmap_light/lightmap_light.png b/data/images/objects/lightmap_light/lightmap_light.png index ac2a707f7..b8cf5f91b 100644 Binary files a/data/images/objects/lightmap_light/lightmap_light.png and b/data/images/objects/lightmap_light/lightmap_light.png differ diff --git a/data/images/objects/lightmap_light/lightmap_light.sprite b/data/images/objects/lightmap_light/lightmap_light.sprite index aa5d9cd85..862c0df5f 100644 --- a/data/images/objects/lightmap_light/lightmap_light.sprite +++ b/data/images/objects/lightmap_light/lightmap_light.sprite @@ -2,6 +2,6 @@ (action (name "default") (images "lightmap_light.png") - (hitbox 100 100 200 200) + (hitbox 256 256 0 0) ) ) diff --git a/src/object/light.cpp b/src/object/light.cpp index ba08bc68f..1675cf275 100644 --- a/src/object/light.cpp +++ b/src/object/light.cpp @@ -27,7 +27,7 @@ #include "player.hpp" #include "sector.hpp" -Light::Light(const lisp::Lisp& ) +Light::Light(const Vector& center, const Color& color) : position(center), color(color) { sprite = sprite_manager->create("images/objects/lightmap_light/lightmap_light.sprite"); } @@ -48,9 +48,10 @@ Light::draw(DrawingContext& context) context.push_target(); context.set_target(DrawingContext::LIGHTMAP); - sprite->draw(context, Sector::current()->player->get_pos(), 0); + sprite->set_color(color); + sprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE)); + sprite->draw(context, position, 0); context.pop_target(); } -IMPLEMENT_FACTORY(Light, "light"); diff --git a/src/object/light.hpp b/src/object/light.hpp index b24891fb3..f571ea578 100644 --- a/src/object/light.hpp +++ b/src/object/light.hpp @@ -22,19 +22,23 @@ #include "game_object.hpp" #include "lisp/lisp.hpp" +#include "math/vector.hpp" +#include "video/color.hpp" class Sprite; class Light : public GameObject { public: - Light(const lisp::Lisp& reader); + Light(const Vector& center, const Color& color = Color(1.0, 1.0, 1.0, 1.0)); virtual ~Light(); void update(float elapsed_time); void draw(DrawingContext& context); private: + Vector position; + Color color; Sprite* sprite; }; diff --git a/src/sector.cpp b/src/sector.cpp index c141f26ec..fa931d4af 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -55,6 +55,7 @@ #include "object/coin.hpp" #include "object/block.hpp" #include "object/invisible_block.hpp" +#include "object/light.hpp" #include "object/bullet.hpp" #include "object/text_object.hpp" #include "object/portable.hpp" @@ -378,6 +379,36 @@ Sector::fix_old_tiles() } } } + + // add lights for special tiles + for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); i++) { + TileMap* tm = dynamic_cast(*i); + if (!tm) continue; + for(size_t x=0; x < tm->get_width(); ++x) { + for(size_t y=0; y < tm->get_height(); ++y) { + const Tile* tile = tm->get_tile(x, y); + Vector pos(tm->get_x_offset() + x*32, tm->get_y_offset() + y*32); + Vector center(pos.x + 16, pos.y + 16); + + // torch + if (tile->getID() == 1517) { + add_object(new Light(center, Color(1.0, 0.6, 0.3, 1.0))); + } + // lava or lavaflow + if ((tile->getID() == 173) || (tile->getID() == 1700) || (tile->getID() == 1705) || (tile->getID() == 1706)) { + // space lights a bit + 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))); + } + } + + } + } + } + + } void