moved some more sprites
[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.hpp"
22 #include "game_session.hpp"
23 #include "resources.hpp"
24 #include "object_factory.hpp"
25 #include "sprite/sprite.hpp"
26 #include "sprite/sprite_manager.hpp"
27 #include "video/drawing_context.hpp"
28 #include "lisp/lisp.hpp"
29 #include "lisp/writer.hpp"
30
31 Door::Door(const lisp::Lisp& reader)
32 {
33   reader.get("x", bbox.p1.x);
34   reader.get("y", bbox.p1.y);
35   bbox.set_size(32, 64);
36
37   reader.get("sector", target_sector);
38   reader.get("spawnpoint", target_spawnpoint);
39
40   sprite = sprite_manager->create("images/objects/door/door.sprite");
41 }
42
43 Door::Door(int x, int y, std::string sector, std::string spawnpoint)
44 {
45   bbox.set_pos(Vector(x, y));
46   bbox.set_size(32, 64);
47   target_sector = sector;
48   target_spawnpoint = spawnpoint;
49
50   sprite = sprite_manager->create("door");
51 }
52
53 Door::~Door()
54 {
55   delete sprite;
56 }
57
58 void
59 Door::write(lisp::Writer& writer)
60 {
61   writer.start_list("door");
62
63   writer.write_float("x", bbox.p1.x);
64   writer.write_float("y", bbox.p1.y);
65   writer.write_float("width", bbox.get_width());
66   writer.write_float("height", bbox.get_height());
67   
68   writer.write_string("sector", target_sector);
69   writer.write_string("spawnpoint", target_spawnpoint);
70
71   writer.end_list("door");
72 }
73
74 void
75 Door::update(float )
76 {
77   //Check if door animation is complete
78   if(sprite->check_animation()) {
79     sprite->set_action("normal");
80     GameSession::current()->respawn(target_sector, target_spawnpoint);
81   }
82 }
83
84 void
85 Door::draw(DrawingContext& context)
86 {
87   sprite->draw(context, bbox.p1, LAYER_TILES);
88 }
89
90 void
91 Door::event(Player& , EventType type)
92 {
93   if(type == EVENT_ACTIVATE) {
94     sprite->set_action("open", 1);
95   }
96 }
97
98 IMPLEMENT_FACTORY(Door, "door");