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.
21 #include "utils/lispreader.h"
22 #include "utils/lispwriter.h"
24 #include "resources.h"
25 #include "special/sprite.h"
26 #include "special/sprite_manager.h"
27 #include "video/drawing_context.h"
28 #include "app/globals.h"
30 using namespace SuperTux;
34 Surface* door_opening[DOOR_OPENING_FRAMES];
36 Door::Door(LispReader& reader)
38 reader.read_float("x", area.x);
39 reader.read_float("y", area.y);
43 reader.read_string("sector", target_sector);
44 reader.read_string("spawnpoint", target_spawnpoint);
46 animation_timer.init(true);
47 door_activated = false;
49 animation_timer.init(true);
52 Door::Door(int x, int y)
59 animation_timer.init(true);
60 door_activated = false;
62 animation_timer.init(true);
66 Door::write(LispWriter& writer)
68 writer.start_list("door");
70 writer.write_float("x", area.x);
71 writer.write_float("y", area.y);
72 writer.write_float("width", area.width);
73 writer.write_float("height", area.height);
75 writer.write_string("sector", target_sector);
76 writer.write_string("spawnpoint", target_spawnpoint);
78 writer.end_list("door");
91 Door::draw(DrawingContext& context)
93 if(animation_timer.check())
94 context.draw_surface(door_opening[(animation_timer.get_gone() * DOOR_OPENING_FRAMES) /
95 DOOR_OPENING_TIME], Vector(area.x, area.y - (door_opening[0]->h/2)), LAYER_TILES);
97 door->draw(context, Vector(area.x, area.y), LAYER_TILES);
99 //Check if door animation is complete
100 //TODO: Move this out of the "draw" method as this is extremely dirty :)
101 if ((!animation_timer.check()) && (door_activated)) {
102 door_activated = false;
103 GameSession::current()->respawn(target_sector, target_spawnpoint);
108 Door::interaction(InteractionType type)
110 //Animate the door on activation
111 //TODO: Resetting the animation doesn't work correctly
112 // Tux and badguys should stop moving while the door is opening
113 if(type == INTERACTION_ACTIVATE) {
114 animation_timer.start(DOOR_OPENING_TIME);
115 door_activated = true;