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