Had a bit of time today and worked on supertux:
[supertux.git] / src / object / coin.cpp
1 #include <config.h>
2
3 #include "coin.h"
4 #include "resources.h"
5 #include "video/drawing_context.h"
6 #include "special/sprite_manager.h"
7 #include "player.h"
8 #include "sector.h"
9 #include "player_status.h"
10 #include "gameobjs.h"
11 #include "statistics.h"
12 #include "object_factory.h"
13
14 Coin::Coin(const Vector& pos)
15 {
16   bbox.set_pos(pos);
17   bbox.set_size(32, 32);
18   sprite = sprite_manager->create("coin");
19 }
20
21 Coin::Coin(const lisp::Lisp& reader)
22 {
23   reader.get("x", bbox.p1.x);
24   reader.get("y", bbox.p1.y);
25   bbox.set_size(32, 32);
26   sprite = sprite_manager->create("coin");
27 }
28
29 Coin::~Coin()
30 {
31   delete sprite;
32 }
33
34 void
35 Coin::action(float )
36 {
37 }
38
39 void
40 Coin::draw(DrawingContext& context)
41 {
42   sprite->draw(context, get_pos(), LAYER_TILES);
43 }
44
45 void
46 Coin::collect()
47 {
48   Sector::current()->player->get_status().incCoins();
49   Sector::current()->add_object(new BouncyCoin(get_pos()));
50   global_stats.add_points(COINS_COLLECTED_STAT, 1);
51   remove_me();
52 }
53
54 HitResponse
55 Coin::collision(GameObject& other, const CollisionHit& )
56 {
57   Player* player = dynamic_cast<Player*>(&other);
58   if(player == 0)
59     return ABORT_MOVE;
60
61   collect();
62   return ABORT_MOVE;
63 }
64
65 IMPLEMENT_FACTORY(Coin, "coin");