added jam build system, please try it out - the advantage would be that it already...
[supertux.git] / src / trigger / 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 #include <config.h>
20
21 #include "door.h"
22 #include "utils/lispreader.h"
23 #include "utils/lispwriter.h"
24 #include "gameloop.h"
25 #include "resources.h"
26 #include "special/sprite.h"
27 #include "special/sprite_manager.h"
28 #include "video/drawing_context.h"
29 #include "app/globals.h"
30
31 using namespace SuperTux;
32
33 Door::Door(LispReader& reader)
34 {
35   reader.read_float("x", bbox.p1.x);
36   reader.read_float("y", bbox.p1.y);
37   bbox.set_size(32, 64);
38
39   reader.read_string("sector", target_sector);
40   reader.read_string("spawnpoint", target_spawnpoint);
41
42   sprite = sprite_manager->create("door");
43 }
44
45 Door::Door(int x, int y)
46 {
47   bbox.set_pos(Vector(x, y));
48   bbox.set_size(32, 64);
49
50   sprite = sprite_manager->create("door");
51 }
52
53 Door::~Door()
54 {
55   delete sprite;
56 }
57
58 void
59 Door::write(LispWriter& writer)
60 {
61   writer.start_list("door");
62
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());
67   
68   writer.write_string("sector", target_sector);
69   writer.write_string("spawnpoint", target_spawnpoint);
70
71   writer.end_list("door");
72 }
73
74 void
75 Door::action(float )
76 {
77   //Check if door animation is complete
78   if (!sprite->check_animation()) {
79     GameSession::current()->respawn(target_sector, target_spawnpoint);
80   }
81 }
82
83 void
84 Door::draw(DrawingContext& context)
85 {
86   sprite->draw(context, bbox.p1, LAYER_TILES);
87 }
88
89 void
90 Door::event(Player& , EventType type)
91 {
92   if(type == EVENT_ACTIVATE) {
93     sprite->set_action("open");
94     sprite->start_animation(1);
95   }
96 }
97