fixed critical telephone bug (thanks for noticing, Matze)
[supertux.git] / src / object / infoblock.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 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
19 //  02111-1307, USA.
20
21 #include <config.h>
22
23 #include "infoblock.h"
24 #include "game_session.h"
25 #include "resources.h"
26 #include "sprite/sprite_manager.h"
27 #include "object_factory.h"
28 #include "lisp/lisp.h"
29 #include "sector.h"
30
31 InfoBlock::InfoBlock(const lisp::Lisp& lisp)
32   : Block(sprite_manager->create("infoblock"))
33 {
34   Vector pos;
35   lisp.get("x", pos.x);
36   lisp.get("y", pos.y);
37   bbox.set_pos(pos);
38
39   if(!lisp.get("message", message)) {
40     std::cerr << "No message in InfoBlock!\n";
41   }
42   stopped = false;
43   ringing = new AmbientSound(get_pos(), 0.5, 300, 1, "phone");
44   Sector::current()->add_object(ringing);  
45 }
46
47 InfoBlock::~InfoBlock()
48 {
49 }
50
51 void
52 InfoBlock::hit(Player& )
53 {
54   GameSession::current()->display_info_box(message);
55   start_bounce();
56   if (!stopped) {
57     ringing->remove_me();
58     stopped = true;
59   }
60 }
61
62 IMPLEMENT_FACTORY(InfoBlock, "infoblock")