moved over some changes from cvs
[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         explode();
59       }
60       break;
61     case 1:
62       if(timer.check()) {
63         remove_me();
64       }
65       break;
66   } 
67 }
68
69 void
70 Bomb::explode()
71 {
72   state = 1;
73   sprite->set_action("explosion");
74   SoundManager::get()->play_sound(IDToSound(SND_EXPLODE), get_pos(),
75       Sector::current()->player->get_pos());
76   timer.start(EXPLOSIONTIME);
77 }
78
79 void
80 Bomb::kill_fall()
81 {
82   explode();
83 }
84