Easter Egg Demo Level:
[supertux.git] / src / trigger / door.cpp
1 //  $Id$
2 //
3 //  SuperTux -  A Jump'n Run
4 //  Copyright (C) 2004 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 #include <config.h>
20
21 #include "door.h"
22 #include "gameloop.h"
23 #include "resources.h"
24 #include "object_factory.h"
25 #include "special/sprite.h"
26 #include "special/sprite_manager.h"
27 #include "video/drawing_context.h"
28 #include "app/globals.h"
29 #include "lisp/lisp.h"
30 #include "lisp/writer.h"
31
32 using namespace SuperTux;
33
34 Door::Door(const lisp::Lisp& reader)
35 {
36   reader.get("x", bbox.p1.x);
37   reader.get("y", bbox.p1.y);
38   bbox.set_size(32, 64);
39
40   reader.get("sector", target_sector);
41   reader.get("spawnpoint", target_spawnpoint);
42
43   sprite = sprite_manager->create("door");
44 }
45
46 Door::Door(int x, int y, std::string sector, std::string spawnpoint)
47 {
48   bbox.set_pos(Vector(x, y));
49   bbox.set_size(32, 64);
50   target_sector = sector;
51   target_spawnpoint = spawnpoint;
52
53   sprite = sprite_manager->create("door");
54 }
55
56 Door::~Door()
57 {
58   delete sprite;
59 }
60
61 void
62 Door::write(lisp::Writer& writer)
63 {
64   writer.start_list("door");
65
66   writer.write_float("x", bbox.p1.x);
67   writer.write_float("y", bbox.p1.y);
68   writer.write_float("width", bbox.get_width());
69   writer.write_float("height", bbox.get_height());
70   
71   writer.write_string("sector", target_sector);
72   writer.write_string("spawnpoint", target_spawnpoint);
73
74   writer.end_list("door");
75 }
76
77 void
78 Door::action(float )
79 {
80   //Check if door animation is complete
81   if(sprite->check_animation()) {
82     GameSession::current()->respawn(target_sector, target_spawnpoint);
83   }
84 }
85
86 void
87 Door::draw(DrawingContext& context)
88 {
89   sprite->draw(context, bbox.p1, LAYER_TILES);
90 }
91
92 void
93 Door::event(Player& , EventType type)
94 {
95   if(type == EVENT_ACTIVATE) {
96     sprite->set_action("open", 1);
97   }
98 }
99
100 IMPLEMENT_FACTORY(Door, "door");