added jam build system, please try it out - the advantage would be that it already...
[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(32, 32);
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(LispWriter& )
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 void
45 Bomb::active_action(float )
46 {
47   switch(state) {
48     case 0:
49       if(timer.check()) {
50         state = 1;
51         sprite->set_action("explosion");
52         timer.start(EXPLOSIONTIME);
53       }
54       break;
55     case 1:
56       if(timer.check()) {
57         remove_me();
58       }
59       break;
60   } 
61 }
62
63 void
64 Bomb::kill_fall()
65 {
66 }