5 static const float WALKSPEED = 80;
7 Spiky::Spiky(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("spiky");
16 Spiky::write(lisp::Writer& writer)
18 writer.start_list("spiky");
20 writer.write_float("x", start_position.x);
21 writer.write_float("y", start_position.y);
23 writer.end_list("spiky");
29 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
30 sprite->set_action(dir == LEFT ? "left" : "right");
34 Spiky::collision_solid(GameObject& , const CollisionHit& hit)
36 if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
37 physic.set_velocity_y(0);
38 } else { // hit right or left
39 dir = dir == LEFT ? RIGHT : LEFT;
40 sprite->set_action(dir == LEFT ? "left" : "right");
41 physic.set_velocity_x(-physic.get_velocity_x());
48 Spiky::collision_badguy(BadGuy& , const CollisionHit& hit)
50 if(fabsf(hit.normal.x) > .8) { // left or right
51 dir = dir == LEFT ? RIGHT : LEFT;
52 sprite->set_action(dir == LEFT ? "left" : "right");
53 physic.set_velocity_x(-physic.get_velocity_x());
59 IMPLEMENT_FACTORY(Spiky, "spiky")