2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "trigger/secretarea_trigger.hpp"
19 #include "object/tilemap.hpp"
20 #include "supertux/level.hpp"
21 #include "supertux/main.hpp"
22 #include "supertux/object_factory.hpp"
23 #include "supertux/resources.hpp"
24 #include "supertux/sector.hpp"
25 #include "util/gettext.hpp"
26 #include "util/reader.hpp"
27 #include "util/writer.hpp"
29 static const float MESSAGE_TIME=3.5;
31 SecretAreaTrigger::SecretAreaTrigger(const Reader& reader) :
34 reader.get("x", bbox.p1.x);
35 reader.get("y", bbox.p1.y);
37 reader.get("width", w);
38 reader.get("height", h);
40 reader.get("fade-tilemap", fade_tilemap);
42 message_displayed = false;
45 SecretAreaTrigger::SecretAreaTrigger(const Rect& area, std::string fade_tilemap)
46 : fade_tilemap(fade_tilemap)
49 message_displayed = false;
52 SecretAreaTrigger::~SecretAreaTrigger()
57 SecretAreaTrigger::draw(DrawingContext& context)
59 if (message_timer.started()) {
60 context.push_transform();
61 context.set_translation(Vector(0, 0));
62 Vector pos = Vector(0, SCREEN_HEIGHT/2 - normal_font->get_height()/2);
63 context.draw_center_text(normal_font, _("You found a secret area!"), pos, LAYER_GUI, SecretAreaTrigger::text_color);
64 context.pop_transform();
66 if (message_timer.check()) {
72 SecretAreaTrigger::event(Player& , EventType type)
74 if(type == EVENT_TOUCH) {
75 if (!message_displayed) {
76 message_timer.start(MESSAGE_TIME);
77 message_displayed = true;
78 Sector::current()->get_level()->stats.secrets++;
80 if (fade_tilemap != "") {
82 Sector& sector = *Sector::current();
83 for(Sector::GameObjects::iterator i = sector.gameobjects.begin(); i != sector.gameobjects.end(); ++i) {
84 TileMap* tm = dynamic_cast<TileMap*>(*i);
86 if (tm->get_name() != fade_tilemap) continue;
95 IMPLEMENT_FACTORY(SecretAreaTrigger, "secretarea");