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 // Can only be killed when jumping, no idea why
15 // Stop actions when pause button is hit (probably a general problem of timers)
16 Nolok_01::Nolok_01(LispReader& reader)
18 reader.read_float("x", start_position.x);
19 reader.read_float("y", start_position.y);
20 bbox.set_size(31.8, 63.8);
21 sprite = sprite_manager->create("dummyguy");
24 Nolok_01::Nolok_01(float pos_x, float pos_y)
26 start_position.x = pos_x;
27 start_position.y = pos_y;
28 bbox.set_size(31.8, 63.8);
29 sprite = sprite_manager->create("dummyguy");
33 Nolok_01::write(LispWriter& writer)
35 writer.start_list("nolok01");
37 writer.write_float("x", get_pos().x);
38 writer.write_float("y", get_pos().y);
40 writer.end_list("nolok01");
46 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
47 sprite->set_action(dir == LEFT ? "left" : "right");
49 action_timer.start(WALK_TIME);
53 Nolok_01::active_action(float elapsed_time)
55 movement = physic.get_movement(elapsed_time);
56 if (action_timer.check()) {
57 if (action == WALKING) {
58 physic.set_velocity_y(700);
60 action_timer.start(JUMP_TIME);
62 else if (action == JUMPING) {
63 sprite->set_action("throw");
65 action_timer.start(SHOOT_TIME);
67 else if (action == SHOOTING) {
68 Sector::current()->add_object(new BouncingSnowball(get_pos().x - 64, get_pos().y, LEFT));
69 Sector::current()->add_object(new BouncingSnowball(get_pos().x + 64, get_pos().y, RIGHT));
70 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
71 sprite->set_action(dir == LEFT ? "left" : "right");
73 action_timer.start(WALK_TIME);
79 Nolok_01::collision_squished(Player& player)
81 sprite->set_action("dead");
82 kill_squished(player);
83 Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
88 Nolok_01::collision_solid(GameObject& , const CollisionHit& hit)
90 if(fabsf(hit.normal.y) > .5){ // hit floor or roof?
91 if (action != JUMPING) physic.set_velocity_y(0);
92 } else { // hit right or left
93 dir = dir == LEFT ? RIGHT : LEFT;
94 sprite->set_action(dir == LEFT ? "left" : "right");
95 physic.set_velocity_x(-physic.get_velocity_x());