-Incorporated Marcin Ko��cielnicki patch that reintroduces the flying
[supertux.git] / src / badguy / jumpy.cpp
1 #include <config.h>
2
3 #include "jumpy.h"
4
5 static const float JUMPSPEED=600;
6
7 Jumpy::Jumpy(const lisp::Lisp& reader)
8 {
9   reader.get("x", start_position.x);
10   reader.get("y", start_position.y);
11   bbox.set_size(31.8, 31.8);
12   sprite = sprite_manager->create("jumpy");
13 }
14
15 void
16 Jumpy::write(lisp::Writer& writer)
17 {
18   writer.start_list("jumpy");
19
20   writer.write_float("x", start_position.x);
21   writer.write_float("y", start_position.y);
22
23   writer.end_list("jumpy");
24 }
25
26 HitResponse
27 Jumpy::collision_solid(GameObject& , const CollisionHit& chit)
28 {
29   return hit(chit);
30 }
31
32 HitResponse
33 Jumpy::collision_badguy(BadGuy& , const CollisionHit& chit)
34 {
35   return hit(chit);
36 }
37
38 HitResponse
39 Jumpy::hit(const CollisionHit& chit)
40 {
41   // hit floor?
42   if(chit.normal.y < -.5) {
43     physic.set_velocity_y(JUMPSPEED);
44   } else if(chit.normal.y < .5) { // bumped on roof
45     physic.set_velocity_y(0);
46   }
47
48   return CONTINUE;
49 }
50
51 void
52 Jumpy::active_action(float elapsed_time)
53 {
54   BadGuy::active_action(elapsed_time);
55   
56   dir = Sector::current()->player->get_pos().x > get_pos().x
57     ? RIGHT : LEFT;
58     //FIXME: add middle and up here
59   sprite->set_action(dir == LEFT ? "left-down" : "right-down");
60 }