4 // Copyright (C) 2005 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
23 #include "secretarea_trigger.h"
24 #include "game_session.h"
25 #include "lisp/lisp.h"
26 #include "lisp/writer.h"
27 #include "object_factory.h"
29 #define MESSAGE_TIME 3.5
31 //TODO: Count numbers of triggered/total secret areas
32 SecretAreaTrigger::SecretAreaTrigger(const lisp::Lisp& 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);
41 reader.get("message", message);
42 message_displayed = false;
45 SecretAreaTrigger::SecretAreaTrigger(const Rectangle& area)
48 message = "You found a secret area!";
49 message_displayed = false;
52 SecretAreaTrigger::~SecretAreaTrigger()
57 SecretAreaTrigger::write(lisp::Writer& writer)
59 writer.start_list("secretarea");
61 writer.write_float("x", bbox.p1.x);
62 writer.write_float("y", bbox.p1.y);
63 writer.write_float("width", bbox.get_width());
64 writer.write_float("height", bbox.get_height());
65 writer.write_string("message", message);
67 writer.end_list("secretarea");
71 SecretAreaTrigger::draw(DrawingContext& context)
73 if (message_timer.started()) {
74 context.push_transform();
75 context.set_translation(Vector(0, 0));
76 Vector pos = Vector(0, SCREEN_HEIGHT/2 - gold_text->get_height()/2);
77 context.draw_center_text(gold_text, message, pos, LAYER_GUI);
78 context.pop_transform();
80 if (message_timer.check()) {
86 SecretAreaTrigger::event(Player& , EventType type)
88 if(type == EVENT_TOUCH) {
89 if (!message_displayed) {
90 message_timer.start(MESSAGE_TIME);
91 message_displayed = true;
96 IMPLEMENT_FACTORY(SecretAreaTrigger, "secretarea");