5 static const float WALKSPEED = 80;
7 SnowBall::SnowBall(const lisp::Lisp& reader)
9 reader.get("x", start_position.x);
10 reader.get("y", start_position.y);
11 bbox.set_size(31.8, 31.8);
12 sprite = sprite_manager->create("snowball");
13 set_direction = false;
16 SnowBall::SnowBall(float pos_x, float pos_y, Direction d)
18 start_position.x = pos_x;
19 start_position.y = pos_y;
20 bbox.set_size(31.8, 31.8);
21 sprite = sprite_manager->create("snowball");
23 initial_direction = d;
27 SnowBall::write(lisp::Writer& writer)
29 writer.start_list("snowball");
31 writer.write_float("x", start_position.x);
32 writer.write_float("y", start_position.y);
34 writer.end_list("snowball");
40 if (set_direction) {dir = initial_direction;}
41 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
42 sprite->set_action(dir == LEFT ? "left" : "right");
46 SnowBall::collision_squished(Player& player)
48 sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
49 kill_squished(player);
54 SnowBall::collision_solid(GameObject& , const CollisionHit& hit)
56 if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
57 physic.set_velocity_y(0);
58 } else { // hit right or left
59 dir = dir == LEFT ? RIGHT : LEFT;
60 sprite->set_action(dir == LEFT ? "left" : "right");
61 physic.set_velocity_x(-physic.get_velocity_x());
68 SnowBall::collision_badguy(BadGuy& , const CollisionHit& hit)
70 if(fabsf(hit.normal.x) > .8) { // left or right hit
71 dir = dir == LEFT ? RIGHT : LEFT;
72 sprite->set_action(dir == LEFT ? "left" : "right");
73 physic.set_velocity_x(-physic.get_velocity_x());
79 IMPLEMENT_FACTORY(SnowBall, "snowball")