3 #include "bouncing_snowball.h"
5 static const float JUMPSPEED = 450;
6 static const float WALKSPEED = 80;
8 BouncingSnowball::BouncingSnowball(const lisp::Lisp& reader)
10 reader.get("x", start_position.x);
11 reader.get("y", start_position.y);
12 bbox.set_size(31.8, 31.8);
13 sprite = sprite_manager->create("bouncingsnowball");
14 set_direction = false;
17 BouncingSnowball::BouncingSnowball(float pos_x, float pos_y, Direction d)
19 start_position.x = pos_x;
20 start_position.y = pos_y;
21 bbox.set_size(31.8, 31.8);
22 sprite = sprite_manager->create("bouncingsnowball");
24 initial_direction = d;
28 BouncingSnowball::write(lisp::Writer& writer)
30 writer.start_list("bouncingsnowball");
32 writer.write_float("x", start_position.x);
33 writer.write_float("y", start_position.y);
35 writer.end_list("bouncingsnowball");
39 BouncingSnowball::activate()
41 if (set_direction) {dir = initial_direction;}
42 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
43 sprite->set_action(dir == LEFT ? "left" : "right");
47 BouncingSnowball::collision_squished(Player& player)
49 sprite->set_action("squished");
50 kill_squished(player);
55 BouncingSnowball::collision_solid(GameObject& , const CollisionHit& hit)
57 if(hit.normal.y < -.5) { // hit floor
58 physic.set_velocity_y(JUMPSPEED);
59 } else if(hit.normal.y > .5) { // bumped on roof
60 physic.set_velocity_y(0);
61 } else { // left or right collision
62 dir = dir == LEFT ? RIGHT : LEFT;
63 sprite->set_action(dir == LEFT ? "left" : "right");
64 physic.set_velocity_x(-physic.get_velocity_x());
71 BouncingSnowball::collision_badguy(BadGuy& , const CollisionHit& hit)
73 if(fabsf(hit.normal.x) > .8) { // left/right?
74 dir = dir == LEFT ? RIGHT : LEFT;
75 sprite->set_action(dir == LEFT ? "left" : "right");
76 physic.set_velocity_x(-physic.get_velocity_x());
77 } else if(hit.normal.y < -.8) { // grounf
78 physic.set_velocity_y(JUMPSPEED);
84 IMPLEMENT_FACTORY(BouncingSnowball, "bouncingsnowball")