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");
17 BouncingSnowball::write(LispWriter& writer)
19 writer.start_list("bouncingsnowball");
21 writer.write_float("x", get_pos().x);
22 writer.write_float("y", get_pos().y);
24 writer.end_list("bouncingsnowball");
28 BouncingSnowball::activate()
30 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
31 sprite->set_action(dir == LEFT ? "left" : "right");
35 BouncingSnowball::collision_squished(Player& player)
37 sprite->set_action("squished");
38 kill_squished(player);
43 BouncingSnowball::collision_solid(GameObject& , const CollisionHit& hit)
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());