5787019d4ffdc8485d26fa7cca2c21222b2e62e5
[supertux.git] / src / trigger / sequence_trigger.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 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  02111-1307, USA.
19
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 = 0, h = 0;
34   reader.get("width", w);
35   reader.get("height", h);
36   bbox.set_size(w, h);
37   reader.get("sequence", sequence_name);
38   triggerevent = EVENT_TOUCH;
39 }
40
41 SequenceTrigger::SequenceTrigger(const Vector& pos, const std::string& sequence)
42 {
43   bbox.set_pos(pos);
44   bbox.set_size(32, 32);
45   sequence_name = sequence;
46   triggerevent = EVENT_TOUCH;
47 }
48
49 SequenceTrigger::~SequenceTrigger()
50 {
51 }
52
53 void
54 SequenceTrigger::write(lisp::Writer& writer)
55 {
56   writer.start_list("sequencetrigger");
57
58   writer.write("x", bbox.p1.x);
59   writer.write("y", bbox.p1.y);
60   writer.write("width", bbox.get_width());
61   writer.write("height", bbox.get_height());
62   writer.write("sequence", sequence_name);
63
64   writer.end_list("sequencetrigger");
65 }
66
67 void
68 SequenceTrigger::event(Player& player, EventType type)
69 {
70   if(type == triggerevent) {
71     player.trigger_sequence(sequence_name);
72   }
73 }
74
75 IMPLEMENT_FACTORY(SequenceTrigger, "sequencetrigger")