359b4522dff414e7d2e8218ddda45aef73e79359
[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 "scene.h"
10 #include "gameobjs.h"
11 #include "statistics.h"
12
13 Coin::Coin(const Vector& pos)
14 {
15   bbox.set_pos(pos);
16   bbox.set_size(32, 32);
17   sprite = sprite_manager->create("coin");
18 }
19
20 Coin::~Coin()
21 {
22   delete sprite;
23 }
24
25 void
26 Coin::action(float )
27 {
28 }
29
30 void
31 Coin::draw(DrawingContext& context)
32 {
33   sprite->draw(context, get_pos(), LAYER_TILES);
34 }
35
36 void
37 Coin::collect()
38 {
39   Sector::current()->player->get_status().incCoins();
40   Sector::current()->add_object(new BouncyCoin(get_pos()));
41   global_stats.add_points(COINS_COLLECTED_STAT, 1);
42   remove_me();
43 }
44
45 HitResponse
46 Coin::collision(GameObject& other, const CollisionHit& )
47 {
48   Player* player = dynamic_cast<Player*>(&other);
49   if(player == 0)
50     return ABORT_MOVE;
51
52   collect();
53   return ABORT_MOVE;
54 }
55