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