- read gravity has real, instead of int
[supertux.git] / src / 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
20 #include "door.h"
21 #include "lispreader.h"
22 #include "lispwriter.h"
23 #include "gameloop.h"
24 #include "resources.h"
25 #include "sprite.h"
26 #include "sprite_manager.h"
27 #include "screen/drawing_context.h"
28
29 Door::Door(LispReader& reader)
30 {
31   reader.read_float("x", area.x);
32   reader.read_float("y", area.y);
33   area.width = 32;
34   area.height = 64;
35
36   reader.read_string("sector", target_sector);
37   reader.read_string("spawnpoint", target_spawnpoint);
38
39   sprite = sprite_manager->load("door");
40   animation_timer.init(true);
41   door_activated = false;
42 }
43
44 void
45 Door::write(LispWriter& writer)
46 {
47   writer.start_list("door");
48
49   writer.write_float("x", area.x);
50   writer.write_float("y", area.y);
51   writer.write_float("width", area.width);
52   writer.write_float("height", area.height);
53   
54   writer.write_string("sector", target_sector);
55   writer.write_string("spawnpoint", target_spawnpoint);
56
57   writer.end_list("door");
58 }
59
60 Door::~Door()
61 {
62 }
63
64 void
65 Door::action(float )
66 {
67 }
68
69 void
70 Door::draw(DrawingContext& context)
71 {
72   sprite->draw(context, Vector(area.x, area.y), LAYER_TILES);
73   
74   //Check if door animation is complete
75   //TODO: Move this out of the "draw" method as this is extremely dirty :)  
76   if ((!animation_timer.check()) && (door_activated)) {    
77     door_activated = false;
78     sprite = sprite_manager->load("door");
79     GameSession::current()->respawn(target_sector, target_spawnpoint);
80   }
81 }
82
83 void
84 Door::interaction(InteractionType type)
85 {
86   //Animate the door on activation
87   //TODO: Resetting the animation doesn't work correctly
88   //      Tux and badguys should stop moving while the door is opening
89   if(type == INTERACTION_ACTIVATE) {
90     sprite = sprite_manager->load("openingdoor");
91     sprite->reset();
92     animation_timer.start(ANIM_TIME);
93     door_activated = true;
94   }
95 }
96