From: Christoph Sommer Date: Wed, 26 Jul 2006 15:19:58 +0000 (+0000) Subject: SecretArea triggers can make tilemaps fade away. See test level. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=53e0fad068502dde636ba32798aa5311bbf3e90b;p=supertux.git SecretArea triggers can make tilemaps fade away. See test level. SVN-Revision: 4093 --- diff --git a/data/levels/test/secret.stl b/data/levels/test/secret.stl new file mode 100644 index 000000000..f70e01568 --- /dev/null +++ b/data/levels/test/secret.stl @@ -0,0 +1,53 @@ +(supertux-level + (version 2) + (name (_ "Totem Test")) + (author "Marek") + (sector + (name "main") + (gravity 1) + (background + (speed 0.5) + (image "images/background/arctis.jpg") + ) + (tilemap + (z-pos -100) + (solid #f) + (speed 1) + (width 30) + (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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 61 1007 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 61 1011 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1004 1015 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1008 1011 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1012 1015 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1008 1011 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1012 1015 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1008 1011 0 0 0 0 0 0 0 0 0 0 0 1000 1001 1002 1002 1002 1002 1002 1002 1002 1002 1002 1002 1002 1002 1002 1002 1002 1034 1015 0 0 0 0 0 0 0 0 0 0 0 1004 1005 1006 1006 1006 1006 1006 1006 1006 1006 1006 1006 1006 1006 1006 1006 1006 1040 1011 0 0 0 0 0 0 0 0 0 0 0 1008 1009 1009 1009 1009 1009 1009 1009 1009 1009 1009 1009 1009 1009 1009 1009 1009 1009 1015 0 0 0 0 0 0 0 0 0 0 0 1016 1017 1018 1017 1018 1017 1018 1009 1009 1009 1013 1014 1009 1009 1009 1009 1009 1009 1011 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1008 1009 1009 1009 1009 1009 1009 1014 1009 1014 1014 1015 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1012 1009 1009 1009 1009 1009 1009 1009 1009 1013 1009 1011 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1008 1009 1009 1009 1009 1009 1009 1009 1014 1009 1013 1035 1001 1002 1002 1002 1002 1002 1002 1001 1002 1001 1002 1001 1002 1001 1002 1002 1002 1002 1034 1009 1013 1014 1009 1014 1014 1013 1009 1009 1009 1041 1005 1006 1006 1006 1006 1006 1006 1005 1006 1005 1006 1005 1006 1005 1006 1005 1006 1006 1040 1009 1009 1009 1009 1013 1009 1009 1009 1013 1014) + ) + (tilemap + (z-pos 100) + (solid #f) + (name "secretcover") + (speed 1) + (width 30) + (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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1008 1009 1009 1009 1009 1009 1009 1009 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1008 1009 1009 1009 1009 1009 1009 1009 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1008 1009 1009 1009 1009 1009 1009 1009 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1008 1009 1009 1009 1009 1009 1009 1009 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1034 1009 1009 1009 1009 1009 1009 1009 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1040 1009 1009 1009 1009 1009 1009 1009 0 0 0 0 0 0 0 0 0 0) + ) + (camera + (mode "normal") + ) + (spawnpoint + (name "main") + (x 96) + (y 800) + ) + (secretarea + (fade-tilemap "secretcover") + (width 216) + (height 168) + (x 404) + (y 772) + ) + ) +) diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index 84c7ff628..ebef4abeb 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -39,14 +39,14 @@ TileMap::TileMap() : solid(false), speed(1), width(0), height(0), z_pos(0), x_offset(0), y_offset(0), - drawing_effect(NO_EFFECT) + drawing_effect(NO_EFFECT), alpha(1.0), current_alpha(1.0), remaining_fade_time(0) { tilemanager = tile_manager; } TileMap::TileMap(const lisp::Lisp& reader, TileManager* new_tile_manager) : GameObject(reader), solid(false), speed(1), width(-1), height(-1), z_pos(0), x_offset(0), y_offset(0), - drawing_effect(NO_EFFECT) + drawing_effect(NO_EFFECT), alpha(1.0), current_alpha(1.0), remaining_fade_time(0) { tilemanager = new_tile_manager; if(tilemanager == 0) @@ -80,7 +80,7 @@ TileMap::TileMap(const lisp::Lisp& reader, TileManager* new_tile_manager) TileMap::TileMap(std::string name, int z_pos, bool solid, size_t width, size_t height) : GameObject(name), solid(solid), speed(1), width(0), height(0), z_pos(z_pos), - x_offset(0), y_offset(0), drawing_effect(NO_EFFECT) + x_offset(0), y_offset(0), drawing_effect(NO_EFFECT), alpha(1.0), current_alpha(1.0), remaining_fade_time(0) { tilemanager = tile_manager; @@ -108,8 +108,20 @@ TileMap::write(lisp::Writer& writer) } void -TileMap::update(float ) +TileMap::update(float elapsed_time) { + // handle tilemap fading + if (current_alpha != alpha) { + remaining_fade_time = std::max(0.0f, remaining_fade_time - elapsed_time); + if (remaining_fade_time == 0.0f) { + current_alpha = alpha; + } else { + float amt = (alpha - current_alpha) / (remaining_fade_time / elapsed_time); + if (amt > 0) current_alpha = std::min(current_alpha + amt, alpha); + if (amt < 0) current_alpha = std::max(current_alpha + amt, alpha); + } + } + // FIXME: testing only static int step = 0; if (step++ > 10) { @@ -124,6 +136,8 @@ TileMap::draw(DrawingContext& context) context.push_transform(); if(drawing_effect != 0) context.set_drawing_effect(drawing_effect); + if(current_alpha != 1.0) context.set_alpha(current_alpha); + float trans_x = roundf(context.get_translation().x); float trans_y = roundf(context.get_translation().y); context.set_translation(Vector(trans_x * speed, trans_y * speed)); @@ -243,4 +257,11 @@ TileMap::change_all(uint32_t oldtile, uint32_t newtile) } } +void +TileMap::fade(float alpha, float seconds) +{ + this->alpha = alpha; + this->remaining_fade_time = seconds; +} + IMPLEMENT_FACTORY(TileMap, "tilemap"); diff --git a/src/object/tilemap.hpp b/src/object/tilemap.hpp index 8cc75230d..473a2a86b 100644 --- a/src/object/tilemap.hpp +++ b/src/object/tilemap.hpp @@ -112,6 +112,12 @@ public: return drawing_effect; } + /** + * Start fading the tilemap to opacity given by @c alpha. + * Destination opacity will be reached after @c seconds seconds. + */ + void fade(float alpha, float seconds = 0); + private: typedef std::vector Tiles; Tiles tiles; @@ -126,6 +132,9 @@ private: float y_offset; DrawingEffect drawing_effect; + float alpha; /**< requested tilemap opacity */ + float current_alpha; /**< current tilemap opacity */ + float remaining_fade_time; /**< seconds until requested tilemap opacity is reached */ }; #endif /*SUPERTUX_TILEMAP_H*/ diff --git a/src/trigger/secretarea_trigger.cpp b/src/trigger/secretarea_trigger.cpp index 4c96af7da..5896a5c0d 100644 --- a/src/trigger/secretarea_trigger.cpp +++ b/src/trigger/secretarea_trigger.cpp @@ -28,10 +28,12 @@ #include "sector.hpp" #include "level.hpp" #include "gettext.hpp" +#include "object/tilemap.hpp" static const float MESSAGE_TIME=3.5; SecretAreaTrigger::SecretAreaTrigger(const lisp::Lisp& reader) + : fade_tilemap("") { reader.get("x", bbox.p1.x); reader.get("y", bbox.p1.y); @@ -39,11 +41,13 @@ SecretAreaTrigger::SecretAreaTrigger(const lisp::Lisp& reader) reader.get("width", w); reader.get("height", h); bbox.set_size(w, h); + reader.get("fade-tilemap", fade_tilemap); message_displayed = false; } -SecretAreaTrigger::SecretAreaTrigger(const Rect& area) +SecretAreaTrigger::SecretAreaTrigger(const Rect& area, std::string fade_tilemap) + : fade_tilemap(fade_tilemap) { bbox = area; message_displayed = false; @@ -62,6 +66,7 @@ SecretAreaTrigger::write(lisp::Writer& writer) writer.write_float("y", bbox.p1.y); writer.write_float("width", bbox.get_width()); writer.write_float("height", bbox.get_height()); + writer.write_string("fade-tilemap", fade_tilemap); writer.end_list("secretarea"); } @@ -89,6 +94,17 @@ SecretAreaTrigger::event(Player& , EventType type) message_timer.start(MESSAGE_TIME); message_displayed = true; Sector::current()->get_level()->stats.secrets++; + + // FIXME: testing only + // fade away tilemaps named "secret" + Sector& sector = *Sector::current(); + for(Sector::GameObjects::iterator i = sector.gameobjects.begin(); i != sector.gameobjects.end(); ++i) { + TileMap* tm = dynamic_cast(*i); + if (!tm) continue; + if (tm->get_name() != fade_tilemap) continue; + tm->fade(0.0, 1.0); + } + } } } diff --git a/src/trigger/secretarea_trigger.hpp b/src/trigger/secretarea_trigger.hpp index da8423fea..2f1130fe2 100644 --- a/src/trigger/secretarea_trigger.hpp +++ b/src/trigger/secretarea_trigger.hpp @@ -30,7 +30,7 @@ class SecretAreaTrigger : public TriggerBase, public Serializable { public: SecretAreaTrigger(const lisp::Lisp& reader); - SecretAreaTrigger(const Rect& area); + SecretAreaTrigger(const Rect& area, std::string fade_tilemap = ""); ~SecretAreaTrigger(); void write(lisp::Writer& writer); @@ -40,6 +40,7 @@ public: private: Timer message_timer; bool message_displayed; + std::string fade_tilemap; /**< tilemap to fade away when trigger is activated, or empty if you don't care */ }; #endif