mainly changed #includes to work with the new SuperTux library
[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 "utils/lispreader.h"
22 #include "utils/lispwriter.h"
23 #include "gameloop.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"
29
30 /** data images */
31 Sprite* door;
32 Surface* door_opening[DOOR_OPENING_FRAMES];
33
34 Door::Door(LispReader& reader)
35 {
36   reader.read_float("x", area.x);
37   reader.read_float("y", area.y);
38   area.width = 32;
39   area.height = 64;
40
41   reader.read_string("sector", target_sector);
42   reader.read_string("spawnpoint", target_spawnpoint);
43
44   animation_timer.init(true);
45   door_activated = false;
46
47   animation_timer.init(true);
48 }
49
50 Door::Door(int x, int y)
51 {
52 area.x = x;
53 area.y = y;
54 area.width = 32;
55 area.height = 64;
56
57 animation_timer.init(true);
58 door_activated = false;
59
60 animation_timer.init(true);
61 }
62
63 void
64 Door::write(LispWriter& writer)
65 {
66   writer.start_list("door");
67
68   writer.write_float("x", area.x);
69   writer.write_float("y", area.y);
70   writer.write_float("width", area.width);
71   writer.write_float("height", area.height);
72   
73   writer.write_string("sector", target_sector);
74   writer.write_string("spawnpoint", target_spawnpoint);
75
76   writer.end_list("door");
77 }
78
79 Door::~Door()
80 {
81 }
82
83 void
84 Door::action(float )
85 {
86 }
87
88 void
89 Door::draw(DrawingContext& context)
90 {
91   if(animation_timer.check())
92     context.draw_surface(door_opening[(animation_timer.get_gone() * DOOR_OPENING_FRAMES) /
93           DOOR_OPENING_TIME], Vector(area.x, area.y - (door_opening[0]->h/2)), LAYER_TILES);
94   else
95     door->draw(context, Vector(area.x, area.y), LAYER_TILES);
96   
97   //Check if door animation is complete
98   //TODO: Move this out of the "draw" method as this is extremely dirty :)  
99   if ((!animation_timer.check()) && (door_activated)) {    
100     door_activated = false;
101     GameSession::current()->respawn(target_sector, target_spawnpoint);
102   }
103 }
104
105 void
106 Door::interaction(InteractionType type)
107 {
108   //Animate the door on activation
109   //TODO: Resetting the animation doesn't work correctly
110   //      Tux and badguys should stop moving while the door is opening
111   if(type == INTERACTION_ACTIVATE) {
112     animation_timer.start(DOOR_OPENING_TIME);
113     door_activated = true;
114   }
115 }
116