4 #include "badguy/bouncing_snowball.h"
5 #include "trigger/door.h"
10 #define INITIAL_HITPOINTS 3
12 static const float WALKSPEED = 90;
14 //TODO: Create sprite, limit max number of snowballs
15 // Stop actions when pause button is hit (probably a general problem of timers)
16 Nolok_01::Nolok_01(const lisp::Lisp& reader)
18 reader.get("x", start_position.x);
19 reader.get("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(lisp::Writer& writer)
35 writer.start_list("nolok_01");
37 writer.write_float("x", start_position.x);
38 writer.write_float("y", start_position.y);
40 writer.end_list("nolok_01");
46 hitpoints = INITIAL_HITPOINTS;
47 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
48 sprite->set_action(dir == LEFT ? "left" : "right");
50 action_timer.start(WALK_TIME);
54 Nolok_01::active_action(float elapsed_time)
56 if (action_timer.check()) {
60 sprite->set_action("jump");
61 physic.set_velocity_y(700);
63 action_timer.start(JUMP_TIME);
68 sprite->set_action("throw");
70 action_timer.start(SHOOT_TIME);
75 Sector::current()->add_object(new BouncingSnowball(get_pos().x - 64, get_pos().y, LEFT));
76 Sector::current()->add_object(new BouncingSnowball(get_pos().x + 64, get_pos().y, RIGHT));
77 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
78 sprite->set_action(dir == LEFT ? "left" : "right");
80 action_timer.start(WALK_TIME);
85 movement = physic.get_movement(elapsed_time);
89 Nolok_01::collision_squished(Player& player)
94 sprite->set_action("dead");
95 kill_squished(player);
96 Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
103 Nolok_01::collision_solid(GameObject& , const CollisionHit& hit)
105 if(fabsf(hit.normal.y) > .5){ // hit floor or roof?
106 if (action != JUMPING) physic.set_velocity_y(0);
107 } else { // hit right or left
108 dir = dir == LEFT ? RIGHT : LEFT;
109 sprite->set_action(dir == LEFT ? "left" : "right");
110 physic.set_velocity_x(-physic.get_velocity_x());
116 IMPLEMENT_FACTORY(Nolok_01, "nolok_01")