9495abc92a33913cf2f47a6997641ce3ef7ef364
[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   if(state == 1)
48     badguy.kill_fall();
49   return ABORT_MOVE;
50 }
51
52 void
53 Bomb::active_action(float )
54 {
55   switch(state) {
56     case 0:
57       if(timer.check()) {
58         state = 1;
59         sprite->set_action("explosion");
60         SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), get_pos(),
61             Sector::current()->player->get_pos());
62         timer.start(EXPLOSIONTIME);
63       }
64       break;
65     case 1:
66       if(timer.check()) {
67         remove_me();
68       }
69       break;
70   } 
71 }
72
73 void
74 Bomb::kill_fall()
75 {
76 }
77