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.h"
23 #include "resources.h"
24 #include "object_factory.h"
25 #include "sprite/sprite.h"
26 #include "sprite/sprite_manager.h"
27 #include "video/drawing_context.h"
28 #include "app/globals.h"
29 #include "lisp/lisp.h"
30 #include "lisp/writer.h"
32 using namespace SuperTux;
34 Hatch::Hatch(const lisp::Lisp& reader)
36 reader.get("x", bbox.p1.x);
37 reader.get("y", bbox.p1.y);
38 bbox.set_size(64, 64);
40 reader.get("sector", target_sector);
41 reader.get("spawnpoint", target_spawnpoint);
43 sprite = sprite_manager->create("hatch");
46 Hatch::Hatch(int x, int y, std::string sector, std::string spawnpoint)
48 bbox.set_pos(Vector(x, y));
49 bbox.set_size(64, 64);
50 target_sector = sector;
51 target_spawnpoint = spawnpoint;
53 sprite = sprite_manager->create("hatch");
62 Hatch::write(lisp::Writer& writer)
64 writer.start_list("hatch");
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());
71 writer.write_string("sector", target_sector);
72 writer.write_string("spawnpoint", target_spawnpoint);
74 writer.end_list("hatch");
80 //Check if hatch animation is complete
81 if(sprite->check_animation()) {
82 sprite->set_action("normal");
83 GameSession::current()->respawn(target_sector, target_spawnpoint);
88 Hatch::draw(DrawingContext& context)
90 sprite->draw(context, bbox.p1, LAYER_TILES);
94 Hatch::event(Player& , EventType type)
96 if(type == EVENT_ACTIVATE) {
97 sprite->set_action("open", 1);
101 IMPLEMENT_FACTORY(Hatch, "hatch");