make badguys bounce of each other again, make bombs and kicked mriceblocks kill other...
[supertux.git] / src / badguy / mrbomb.cpp
1 #include <config.h>
2
3 #include "mrbomb.h"
4 #include "bomb.h"
5
6 static const float WALKSPEED = 80;
7
8 MrBomb::MrBomb(const lisp::Lisp& reader)
9 {
10   reader.get("x", start_position.x);
11   reader.get("y", start_position.y);
12   bbox.set_size(31.8, 31.8);
13   sprite = sprite_manager->create("mrbomb");
14   set_direction = false;
15 }
16
17 MrBomb::MrBomb(float pos_x, float pos_y, Direction d)
18 {
19   start_position.x = pos_x;
20   start_position.y = pos_y;
21   bbox.set_size(31.8, 31.8);
22   sprite = sprite_manager->create("mrbomb");
23   set_direction = true;
24   initial_direction = d;
25 }
26
27 void
28 MrBomb::write(lisp::Writer& writer)
29 {
30   writer.start_list("mrbomb");
31
32   writer.write_float("x", get_pos().x);
33   writer.write_float("y", get_pos().y);
34
35   writer.end_list("mrbomb");
36 }
37
38 void
39 MrBomb::activate()
40 {
41   if (set_direction) {dir = initial_direction;}
42   physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
43   sprite->set_action(dir == LEFT ? "left" : "right");
44 }
45
46 bool
47 MrBomb::collision_squished(Player& player)
48 {
49   remove_me();
50   Sector::current()->add_object(new Bomb(get_pos(), dir));
51   player.bounce(*this);
52   return true;
53 }
54
55 HitResponse
56 MrBomb::collision_solid(GameObject& , const CollisionHit& hit)
57 {
58   if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
59     physic.set_velocity_y(0);
60   } else { // hit right or left
61     dir = dir == LEFT ? RIGHT : LEFT;
62     sprite->set_action(dir == LEFT ? "left" : "right");
63     physic.set_velocity_x(-physic.get_velocity_x());
64   }
65
66   return CONTINUE;
67 }
68
69 HitResponse
70 MrBomb::collision_badguy(BadGuy& , const CollisionHit& hit)
71 {
72   if(fabsf(hit.normal.x) > .8) { // left or right
73     dir = dir == LEFT ? RIGHT : LEFT;
74     sprite->set_action(dir == LEFT ? "left" : "right");    
75     physic.set_velocity_x(-physic.get_velocity_x());
76   }
77
78   return CONTINUE;
79 }