changed worldmap format a bit to be more consistent with level format
[supertux.git] / src / object / bell.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 #include <config.h>
21
22 #include "bell.h"
23 #include "resources.h"
24 #include "sprite/sprite_manager.h"
25 #include "video/drawing_context.h"
26 #include "player.h"
27 #include "object_factory.h"
28 #include "game_session.h"
29 #include "sector.h"
30
31 Bell::Bell(const lisp::Lisp& lisp)
32   : ringing(false)
33 {
34   lisp.get("x", bbox.p1.x);
35   lisp.get("y", bbox.p1.y);
36   bbox.set_size(32, 32);
37   sprite = sprite_manager->create("bell");
38 }
39
40 Bell::~Bell()
41 {
42   delete sprite;
43 }
44
45 void
46 Bell::write(lisp::Writer& writer)
47 {
48   writer.start_list("bell");
49   writer.write_float("x", bbox.p1.x);
50   writer.write_float("y", bbox.p1.y);
51   writer.end_list("bell");
52 }
53
54 void
55 Bell::update(float )
56 {
57 }
58
59 void
60 Bell::draw(DrawingContext& context)
61 {
62   sprite->draw(context, get_pos(), LAYER_TILES);
63 }
64
65 HitResponse
66 Bell::collision(GameObject& other, const CollisionHit& )
67 {
68   if(ringing)
69     return ABORT_MOVE;
70   
71   Player* player = dynamic_cast<Player*> (&other);
72   if(player) {
73     ringing = true;
74     // TODO play sound
75     sprite->set_action("ringing");
76     GameSession::current()->set_reset_point(Sector::current()->get_name(),
77         get_pos());
78   }
79   
80   return ABORT_MOVE;
81 }
82
83 IMPLEMENT_FACTORY(Bell, "bell");