3 #include "bouncing_snowball.h"
5 static const float JUMPSPEED = 450;
6 static const float WALKSPEED = 80;
8 BouncingSnowball::BouncingSnowball(LispReader& reader)
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");
16 BouncingSnowball::BouncingSnowball(float pos_x, float pos_y)
18 start_position.x = pos_x;
19 start_position.y = pos_y;
20 bbox.set_size(32, 32);
21 sprite = sprite_manager->create("bouncingsnowball");
25 BouncingSnowball::write(LispWriter& writer)
27 writer.start_list("bouncingsnowball");
29 writer.write_float("x", get_pos().x);
30 writer.write_float("y", get_pos().y);
32 writer.end_list("bouncingsnowball");
36 BouncingSnowball::activate()
38 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
39 sprite->set_action(dir == LEFT ? "left" : "right");
43 BouncingSnowball::collision_squished(Player& player)
45 sprite->set_action("squished");
46 kill_squished(player);
51 BouncingSnowball::collision_solid(GameObject& , const CollisionHit& hit)
53 if(hit.normal.y < -.5) { // hit floor
54 physic.set_velocity_y(JUMPSPEED);
55 } else if(hit.normal.y > .5) { // bumped on roof
56 physic.set_velocity_y(0);
57 } else { // left or right collision
58 dir = dir == LEFT ? RIGHT : LEFT;
59 sprite->set_action(dir == LEFT ? "left" : "right");
60 physic.set_velocity_x(-physic.get_velocity_x());