3 // SuperTux - A Jump'n Run
4 // Copyright (C) 2004 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.
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"
31 Hatch::Hatch(const lisp::Lisp& reader)
33 reader.get("x", bbox.p1.x);
34 reader.get("y", bbox.p1.y);
35 bbox.set_size(64, 64);
37 reader.get("sector", target_sector);
38 reader.get("spawnpoint", target_spawnpoint);
40 sprite = sprite_manager->create("hatch");
43 Hatch::Hatch(int x, int y, std::string sector, std::string spawnpoint)
45 bbox.set_pos(Vector(x, y));
46 bbox.set_size(64, 64);
47 target_sector = sector;
48 target_spawnpoint = spawnpoint;
50 sprite = sprite_manager->create("hatch");
59 Hatch::write(lisp::Writer& writer)
61 writer.start_list("hatch");
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());
68 writer.write_string("sector", target_sector);
69 writer.write_string("spawnpoint", target_spawnpoint);
71 writer.end_list("hatch");
77 //Check if hatch animation is complete
78 if(sprite->check_animation()) {
79 sprite->set_action("normal");
80 GameSession::current()->respawn(target_sector, target_spawnpoint);
85 Hatch::draw(DrawingContext& context)
87 sprite->draw(context, bbox.p1, LAYER_TILES);
91 Hatch::event(Player& , EventType type)
93 if(type == EVENT_ACTIVATE) {
94 sprite->set_action("open", 1);
98 IMPLEMENT_FACTORY(Hatch, "hatch");