replaced bell object with firefly, renamed all hooks back to bell. Changed phone...
[supertux.git] / src / object / firefly.cpp
1 //  $Id: Firefly.cpp 2979 2006-01-10 00:00:04Z matzebraun $
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 "firefly.hpp"
23 #include "resources.hpp"
24 #include "sprite/sprite_manager.hpp"
25 #include "video/drawing_context.hpp"
26 #include "player.hpp"
27 #include "object_factory.hpp"
28 #include "game_session.hpp"
29 #include "sector.hpp"
30
31 Firefly::Firefly(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("images/objects/firefly/firefly.sprite");
38   set_group(COLGROUP_TOUCHABLE);
39 }
40
41 Firefly::~Firefly()
42 {
43   delete sprite;
44 }
45
46 void
47 Firefly::write(lisp::Writer& writer)
48 {
49   writer.start_list("firefly");
50   writer.write_float("x", bbox.p1.x);
51   writer.write_float("y", bbox.p1.y);
52   writer.end_list("Firefly");
53 }
54
55 void
56 Firefly::update(float )
57 {
58 }
59
60 void
61 Firefly::draw(DrawingContext& context)
62 {
63   sprite->draw(context, get_pos(), LAYER_TILES);
64 }
65
66 HitResponse
67 Firefly::collision(GameObject& other, const CollisionHit& )
68 {
69   if(ringing)
70     return ABORT_MOVE;
71   
72   Player* player = dynamic_cast<Player*> (&other);
73   if(player) {
74     ringing = true;
75     // TODO play sound
76     sprite->set_action("ringing");
77     GameSession::current()->set_reset_point(Sector::current()->get_name(),
78         get_pos());
79   }
80   
81   return ABORT_MOVE;
82 }
83
84 IMPLEMENT_FACTORY(Firefly, "firefly");