4 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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.
23 #include "game_session.hpp"
24 #include "resources.hpp"
25 #include "object_factory.hpp"
26 #include "sprite/sprite.hpp"
27 #include "sprite/sprite_manager.hpp"
28 #include "video/drawing_context.hpp"
29 #include "lisp/lisp.hpp"
30 #include "lisp/writer.hpp"
32 Door::Door(const lisp::Lisp& reader)
34 reader.get("x", bbox.p1.x);
35 reader.get("y", bbox.p1.y);
36 bbox.set_size(32, 64);
38 reader.get("sector", target_sector);
39 reader.get("spawnpoint", target_spawnpoint);
41 sprite = sprite_manager->create("images/objects/door/door.sprite");
44 Door::Door(int x, int y, std::string sector, std::string spawnpoint)
46 bbox.set_pos(Vector(x, y));
47 bbox.set_size(32, 64);
48 target_sector = sector;
49 target_spawnpoint = spawnpoint;
51 sprite = sprite_manager->create("images/objects/door/door.sprite");
60 Door::write(lisp::Writer& writer)
62 writer.start_list("door");
64 writer.write_float("x", bbox.p1.x);
65 writer.write_float("y", bbox.p1.y);
66 writer.write_float("width", bbox.get_width());
67 writer.write_float("height", bbox.get_height());
69 writer.write_string("sector", target_sector);
70 writer.write_string("spawnpoint", target_spawnpoint);
72 writer.end_list("door");
78 //Check if door animation is complete
79 if(sprite->animation_done()) {
80 sprite->set_action("normal");
81 GameSession::current()->respawn(target_sector, target_spawnpoint);
86 Door::draw(DrawingContext& context)
88 sprite->draw(context, bbox.p1, LAYER_TILES);
92 Door::event(Player& , EventType type)
94 if(type == EVENT_ACTIVATE) {
95 sprite->set_action("open", 1);
99 IMPLEMENT_FACTORY(Door, "door");