4 #include "badguy/bouncing_snowball.h"
5 #include "trigger/door.h"
11 static const float WALKSPEED = 90;
13 //TODO: Create sprite, give multiple hitpoints, limit max number of snowballs
14 // Stop actions when pause button is hit (probably a general problem of timers)
15 Nolok_01::Nolok_01(const lisp::Lisp& reader)
17 reader.get("x", start_position.x);
18 reader.get("y", start_position.y);
19 bbox.set_size(31.8, 63.8);
20 sprite = sprite_manager->create("dummyguy");
23 Nolok_01::Nolok_01(float pos_x, float pos_y)
25 start_position.x = pos_x;
26 start_position.y = pos_y;
27 bbox.set_size(31.8, 63.8);
28 sprite = sprite_manager->create("dummyguy");
32 Nolok_01::write(lisp::Writer& writer)
34 writer.start_list("nolok01");
36 writer.write_float("x", start_position.x);
37 writer.write_float("y", start_position.y);
39 writer.end_list("nolok01");
45 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
46 sprite->set_action(dir == LEFT ? "left" : "right");
48 action_timer.start(WALK_TIME);
52 Nolok_01::active_action(float elapsed_time)
54 if (action_timer.check()) {
58 sprite->set_action("jump");
59 physic.set_velocity_y(700);
61 action_timer.start(JUMP_TIME);
66 sprite->set_action("throw");
68 action_timer.start(SHOOT_TIME);
73 Sector::current()->add_object(new BouncingSnowball(get_pos().x - 64, get_pos().y, LEFT));
74 Sector::current()->add_object(new BouncingSnowball(get_pos().x + 64, get_pos().y, RIGHT));
75 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
76 sprite->set_action(dir == LEFT ? "left" : "right");
78 action_timer.start(WALK_TIME);
83 movement = physic.get_movement(elapsed_time);
87 Nolok_01::collision_squished(Player& player)
89 sprite->set_action("dead");
90 kill_squished(player);
91 Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
96 Nolok_01::collision_solid(GameObject& , const CollisionHit& hit)
98 if(fabsf(hit.normal.y) > .5){ // hit floor or roof?
99 if (action != JUMPING) physic.set_velocity_y(0);
100 } else { // hit right or left
101 dir = dir == LEFT ? RIGHT : LEFT;
102 sprite->set_action(dir == LEFT ? "left" : "right");
103 physic.set_velocity_x(-physic.get_velocity_x());
109 IMPLEMENT_FACTORY(Nolok_01, "nolok01")