implemented a new object factory mechanism which is now really independent of the...
[supertux.git] / src / trigger / sequence_trigger.cpp
1 #include <config.h>
2
3 #include "sequence_trigger.h"
4 #include "gameloop.h"
5 #include "lisp/lisp.h"
6 #include "lisp/writer.h"
7 #include "object_factory.h"
8
9 SequenceTrigger::SequenceTrigger(const lisp::Lisp& reader)
10 {
11   reader.get("x", bbox.p1.x);
12   reader.get("y", bbox.p1.y);
13   float w, h;
14   reader.get("width", w);
15   reader.get("height", h);
16   bbox.set_size(w, h);
17   reader.get("sequence", sequence_name);
18 }
19
20 SequenceTrigger::SequenceTrigger(const Vector& pos, const std::string& sequence)
21 {
22   bbox.set_pos(pos);
23   bbox.set_size(32, 32);
24   sequence_name = sequence;
25   triggerevent = EVENT_TOUCH;
26 }
27
28 SequenceTrigger::~SequenceTrigger()
29 {
30 }
31
32 void
33 SequenceTrigger::write(lisp::Writer& writer)
34 {
35   writer.start_list("sequencetrigger");
36
37   writer.write_float("x", bbox.p1.x);
38   writer.write_float("y", bbox.p1.y);
39   writer.write_float("width", bbox.get_width());
40   writer.write_float("height", bbox.get_height());
41   writer.write_string("sequence", sequence_name);
42
43   writer.end_list("sequencetrigger");
44 }
45
46 void
47 SequenceTrigger::event(Player& , EventType type)
48 {
49   if(type == triggerevent) {
50     GameSession::current()->start_sequence(sequence_name);
51   }
52 }
53
54 IMPLEMENT_FACTORY(SequenceTrigger, "sequencetrigger")