00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "trigger/secretarea_trigger.hpp"
00018
00019 #include "object/tilemap.hpp"
00020 #include "supertux/level.hpp"
00021 #include "supertux/globals.hpp"
00022 #include "supertux/object_factory.hpp"
00023 #include "supertux/resources.hpp"
00024 #include "supertux/sector.hpp"
00025 #include "util/gettext.hpp"
00026 #include "util/reader.hpp"
00027 #include "util/writer.hpp"
00028
00029 static const float MESSAGE_TIME=3.5;
00030
00031 SecretAreaTrigger::SecretAreaTrigger(const Reader& reader) :
00032 message_timer(),
00033 message_displayed(),
00034 message(),
00035 fade_tilemap()
00036 {
00037 reader.get("x", bbox.p1.x);
00038 reader.get("y", bbox.p1.y);
00039 float w = 32, h = 32;
00040 reader.get("width", w);
00041 reader.get("height", h);
00042 bbox.set_size(w, h);
00043 reader.get("fade-tilemap", fade_tilemap);
00044 reader.get("message", message);
00045 if(message == "") {
00046 message = _("You found a secret area!");
00047 }
00048
00049 message_displayed = false;
00050 }
00051
00052 SecretAreaTrigger::SecretAreaTrigger(const Rectf& area, std::string fade_tilemap) :
00053 message_timer(),
00054 message_displayed(),
00055 message(_("You found a secret area!")),
00056 fade_tilemap(fade_tilemap)
00057 {
00058 bbox = area;
00059 message_displayed = false;
00060 }
00061
00062 SecretAreaTrigger::~SecretAreaTrigger()
00063 {
00064 }
00065
00066 void
00067 SecretAreaTrigger::draw(DrawingContext& context)
00068 {
00069 if (message_timer.started()) {
00070 context.push_transform();
00071 context.set_translation(Vector(0, 0));
00072 Vector pos = Vector(0, SCREEN_HEIGHT/2 - Resources::normal_font->get_height()/2);
00073 context.draw_center_text(Resources::normal_font, message, pos, LAYER_HUD, SecretAreaTrigger::text_color);
00074 context.pop_transform();
00075 }
00076 if (message_timer.check()) {
00077 remove_me();
00078 }
00079 }
00080
00081 void
00082 SecretAreaTrigger::event(Player& , EventType type)
00083 {
00084 if(type == EVENT_TOUCH) {
00085 if (!message_displayed) {
00086 message_timer.start(MESSAGE_TIME);
00087 message_displayed = true;
00088 Sector::current()->get_level()->stats.secrets++;
00089
00090 if (fade_tilemap != "") {
00091
00092 Sector& sector = *Sector::current();
00093 for(Sector::GameObjects::iterator i = sector.gameobjects.begin(); i != sector.gameobjects.end(); ++i) {
00094 TileMap* tm = dynamic_cast<TileMap*>(*i);
00095 if (!tm) continue;
00096 if (tm->get_name() != fade_tilemap) continue;
00097 tm->fade(0.0, 1.0);
00098 }
00099 }
00100
00101 }
00102 }
00103 }
00104
00105