--- /dev/null
+(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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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 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)
+ (ti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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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 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)
+ )
+ )
+)
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)
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;
}
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) {
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));
}
}
+void
+TileMap::fade(float alpha, float seconds)
+{
+ this->alpha = alpha;
+ this->remaining_fade_time = seconds;
+}
+
IMPLEMENT_FACTORY(TileMap, "tilemap");
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<uint32_t> Tiles;
Tiles tiles;
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*/
#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);
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;
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");
}
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<TileMap*>(*i);
+ if (!tm) continue;
+ if (tm->get_name() != fade_tilemap) continue;
+ tm->fade(0.0, 1.0);
+ }
+
}
}
}
{
public:
SecretAreaTrigger(const lisp::Lisp& reader);
- SecretAreaTrigger(const Rect& area);
+ SecretAreaTrigger(const Rect& area, std::string fade_tilemap = "");
~SecretAreaTrigger();
void write(lisp::Writer& writer);
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