7ef726d9271555c70c9d293bc8f49bb143114dae
[supertux.git] / src / trigger / sequence_trigger.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 Matthias Braun <matze@braunis.de>
5 //
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.
10 //
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.
15 // 
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
19 //  02111-1307, USA.
20
21 #include <config.h>
22
23 #include "sequence_trigger.hpp"
24 #include "game_session.hpp"
25 #include "lisp/lisp.hpp"
26 #include "lisp/writer.hpp"
27 #include "object_factory.hpp"
28
29 SequenceTrigger::SequenceTrigger(const lisp::Lisp& reader)
30 {
31   reader.get("x", bbox.p1.x);
32   reader.get("y", bbox.p1.y);
33   float w, h;
34   reader.get("width", w);
35   reader.get("height", h);
36   bbox.set_size(w, h);
37   reader.get("sequence", sequence_name);
38 }
39
40 SequenceTrigger::SequenceTrigger(const Vector& pos, const std::string& sequence)
41 {
42   bbox.set_pos(pos);
43   bbox.set_size(32, 32);
44   sequence_name = sequence;
45   triggerevent = EVENT_TOUCH;
46 }
47
48 SequenceTrigger::~SequenceTrigger()
49 {
50 }
51
52 void
53 SequenceTrigger::write(lisp::Writer& writer)
54 {
55   writer.start_list("sequencetrigger");
56
57   writer.write_float("x", bbox.p1.x);
58   writer.write_float("y", bbox.p1.y);
59   writer.write_float("width", bbox.get_width());
60   writer.write_float("height", bbox.get_height());
61   writer.write_string("sequence", sequence_name);
62
63   writer.end_list("sequencetrigger");
64 }
65
66 void
67 SequenceTrigger::event(Player& , EventType type)
68 {
69   if(type == triggerevent) {
70     GameSession::current()->start_sequence(sequence_name);
71   }
72 }
73
74 IMPLEMENT_FACTORY(SequenceTrigger, "sequencetrigger")