update statistics again if coins are collected
[supertux.git] / src / badguy / bomb.cpp
1 #include <config.h>
2
3 #include "bomb.h"
4
5 static const float TICKINGTIME = 1;
6 static const float EXPLOSIONTIME = 1;
7
8 Bomb::Bomb(const Vector& pos, Direction dir)
9 {
10   start_position = pos;
11   bbox.set_pos(pos);
12   bbox.set_size(31.8, 31.8);
13   sprite = sprite_manager->create("bomb");
14   state = 0;
15   timer.start(TICKINGTIME);
16   this->dir = dir;
17   sprite->set_action(dir == LEFT ? "ticking-left" : "ticking-right");
18 }
19
20 void
21 Bomb::write(lisp::Writer& )
22 {
23   // bombs are only temporarily so don't write them out...
24 }
25
26 HitResponse
27 Bomb::collision_solid(GameObject& , const CollisionHit& hit)
28 {
29   if(fabsf(hit.normal.y) > .5)
30     physic.set_velocity_y(0);
31
32   return CONTINUE;
33 }
34
35 HitResponse
36 Bomb::collision_player(Player& player, const CollisionHit& )
37 {
38   if(state == 1) {
39     player.kill(Player::SHRINK);
40   }
41   return ABORT_MOVE;
42 }
43
44 HitResponse
45 Bomb::collision_badguy(BadGuy& badguy, const CollisionHit& )
46 {
47   badguy.kill_fall();
48   return ABORT_MOVE;
49 }
50
51 void
52 Bomb::active_action(float )
53 {
54   switch(state) {
55     case 0:
56       if(timer.check()) {
57         state = 1;
58         sprite->set_action("explosion");
59         timer.start(EXPLOSIONTIME);
60       }
61       break;
62     case 1:
63       if(timer.check()) {
64         remove_me();
65       }
66       break;
67   } 
68 }
69
70 void
71 Bomb::kill_fall()
72 {
73 }