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