added a bell object which is a new better way to do reset points
[supertux.git] / src / object / bell.cpp
1 #include <config.h>
2
3 #include "bell.h"
4 #include "resources.h"
5 #include "special/sprite_manager.h"
6 #include "video/drawing_context.h"
7 #include "player.h"
8 #include "object_factory.h"
9 #include "gameloop.h"
10 #include "sector.h"
11
12 Bell::Bell(const lisp::Lisp& lisp)
13   : ringing(false)
14 {
15   lisp.get("x", bbox.p1.x);
16   lisp.get("y", bbox.p1.y);
17   bbox.set_size(32, 32);
18   sprite = sprite_manager->create("bell");
19 }
20
21 Bell::~Bell()
22 {
23   delete sprite;
24 }
25
26 void
27 Bell::write(lisp::Writer& writer)
28 {
29   writer.start_list("bell");
30   writer.write_float("x", bbox.p1.x);
31   writer.write_float("y", bbox.p1.y);
32   writer.end_list("bell");
33 }
34
35 void
36 Bell::action(float )
37 {
38 }
39
40 void
41 Bell::draw(DrawingContext& context)
42 {
43   sprite->draw(context, get_pos(), LAYER_TILES);
44 }
45
46 HitResponse
47 Bell::collision(GameObject& other, const CollisionHit& )
48 {
49   if(ringing)
50     return ABORT_MOVE;
51   
52   Player* player = dynamic_cast<Player*> (&other);
53   if(player) {
54     ringing = true;
55     // TODO play sound
56     sprite->set_action("ringing");
57     GameSession::current()->set_reset_point(Sector::current()->get_name(),
58         get_pos());
59   }
60   
61   return ABORT_MOVE;
62 }
63
64 IMPLEMENT_FACTORY(Bell, "bell");