added jam build system, please try it out - the advantage would be that it already...
[supertux.git] / src / badguy / bouncing_snowball.cpp
1 #include <config.h>
2
3 #include "bouncing_snowball.h"
4
5 static const float JUMPSPEED = 450;
6 static const float WALKSPEED = 80;
7
8 BouncingSnowball::BouncingSnowball(LispReader& reader)
9 {
10   reader.read_float("x", start_position.x);
11   reader.read_float("y", start_position.y);
12   bbox.set_size(32, 32);
13   sprite = sprite_manager->create("bouncingsnowball");
14 }
15
16 void
17 BouncingSnowball::write(LispWriter& writer)
18 {
19   writer.start_list("bouncingsnowball");
20
21   writer.write_float("x", get_pos().x);
22   writer.write_float("y", get_pos().y);
23
24   writer.end_list("bouncingsnowball");
25 }
26
27 void
28 BouncingSnowball::activate()
29 {
30   physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
31   sprite->set_action(dir == LEFT ? "left" : "right");
32 }
33
34 bool
35 BouncingSnowball::collision_squished(Player& player)
36 {
37   sprite->set_action("squished");
38   kill_squished(player);
39   return true;
40 }
41
42 HitResponse
43 BouncingSnowball::collision_solid(GameObject& , const CollisionHit& hit)
44 {
45   if(hit.normal.y < -.5) { // hit floor
46     physic.set_velocity_y(JUMPSPEED);
47   } else if(hit.normal.y > .5) { // bumped on roof
48     physic.set_velocity_y(0);
49   } else { // left or right collision
50     dir = dir == LEFT ? RIGHT : LEFT;
51     sprite->set_action(dir == LEFT ? "left" : "right");
52     physic.set_velocity_x(-physic.get_velocity_x());
53   }
54
55   return CONTINUE;
56 }
57