4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "secretarea_trigger.hpp"
23 #include "game_session.hpp"
24 #include "lisp/lisp.hpp"
25 #include "lisp/writer.hpp"
26 #include "object_factory.hpp"
30 #include "gettext.hpp"
31 #include "object/tilemap.hpp"
33 static const float MESSAGE_TIME=3.5;
35 SecretAreaTrigger::SecretAreaTrigger(const lisp::Lisp& reader)
38 reader.get("x", bbox.p1.x);
39 reader.get("y", bbox.p1.y);
41 reader.get("width", w);
42 reader.get("height", h);
44 reader.get("fade-tilemap", fade_tilemap);
46 message_displayed = false;
49 SecretAreaTrigger::SecretAreaTrigger(const Rect& area, std::string fade_tilemap)
50 : fade_tilemap(fade_tilemap)
53 message_displayed = false;
56 SecretAreaTrigger::~SecretAreaTrigger()
61 SecretAreaTrigger::write(lisp::Writer& writer)
63 writer.start_list("secretarea");
65 writer.write_float("x", bbox.p1.x);
66 writer.write_float("y", bbox.p1.y);
67 writer.write_float("width", bbox.get_width());
68 writer.write_float("height", bbox.get_height());
69 writer.write_string("fade-tilemap", fade_tilemap);
71 writer.end_list("secretarea");
75 SecretAreaTrigger::draw(DrawingContext& context)
77 if (message_timer.started()) {
78 context.push_transform();
79 context.set_translation(Vector(0, 0));
80 Vector pos = Vector(0, SCREEN_HEIGHT/2 - gold_text->get_height()/2);
81 context.draw_center_text(gold_text, _("You found a secret area!"), pos, LAYER_GUI);
82 context.pop_transform();
84 if (message_timer.check()) {
90 SecretAreaTrigger::event(Player& , EventType type)
92 if(type == EVENT_TOUCH) {
93 if (!message_displayed) {
94 message_timer.start(MESSAGE_TIME);
95 message_displayed = true;
96 Sector::current()->get_level()->stats.secrets++;
98 // FIXME: testing only
99 // fade away tilemaps named "secret"
100 Sector& sector = *Sector::current();
101 for(Sector::GameObjects::iterator i = sector.gameobjects.begin(); i != sector.gameobjects.end(); ++i) {
102 TileMap* tm = dynamic_cast<TileMap*>(*i);
104 if (tm->get_name() != fade_tilemap) continue;
112 IMPLEMENT_FACTORY(SecretAreaTrigger, "secretarea");