Some more objects now inherit from MovingSprite
[supertux.git] / src / object / firefly.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 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 <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         : MovingSprite(lisp, "images/objects/firefly/firefly.sprite", LAYER_TILES, COLGROUP_TOUCHABLE), activated(false)
33 {
34 }
35
36 void
37 Firefly::write(lisp::Writer& writer)
38 {
39   writer.start_list("firefly");
40   writer.write_float("x", bbox.p1.x);
41   writer.write_float("y", bbox.p1.y);
42   writer.end_list("firefly");
43 }
44
45 HitResponse
46 Firefly::collision(GameObject& other, const CollisionHit& )
47 {
48   if(activated)
49     return ABORT_MOVE;
50   
51   Player* player = dynamic_cast<Player*> (&other);
52   if(player) {
53     activated = true;
54     // TODO play sound
55     sprite->set_action("ringing");
56     GameSession::current()->set_reset_point(Sector::current()->get_name(),
57         get_pos());
58   }
59   
60   return ABORT_MOVE;
61 }
62
63 IMPLEMENT_FACTORY(Firefly, "firefly");