4 #include "badguy/bouncing_snowball.h"
5 #include "trigger/door.h"
10 #define INITIAL_HITPOINTS 3
11 #define INITIAL_BULLET_HP 10
13 static const float WALKSPEED = 90;
15 //TODO: Create sprite, limit max number of snowballs
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 bullet_hitpoints = INITIAL_BULLET_HP;
48 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
49 sprite->set_action(dir == LEFT ? "left" : "right");
51 action_timer.start(WALK_TIME);
55 Nolok_01::active_action(float elapsed_time)
57 if (action_timer.check()) {
61 sprite->set_action("jump");
62 physic.set_velocity_y(700);
64 action_timer.start(JUMP_TIME);
69 sprite->set_action("throw");
71 action_timer.start(SHOOT_TIME);
76 Sector::current()->add_object(new BouncingSnowball(get_pos().x - 64, get_pos().y, LEFT));
77 Sector::current()->add_object(new BouncingSnowball(get_pos().x + 64, get_pos().y, RIGHT));
78 physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED);
79 sprite->set_action(dir == LEFT ? "left" : "right");
81 action_timer.start(WALK_TIME);
86 movement = physic.get_movement(elapsed_time);
90 Nolok_01::collision_squished(Player& player)
96 sprite->set_action("dead");
97 kill_squished(player);
98 Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
105 Nolok_01::collision_solid(GameObject& , const CollisionHit& hit)
107 if(fabsf(hit.normal.y) > .5){ // hit floor or roof?
108 if (action != JUMPING) physic.set_velocity_y(0);
109 } else { // hit right or left
110 dir = dir == LEFT ? RIGHT : LEFT;
111 sprite->set_action(dir == LEFT ? "left" : "right");
112 physic.set_velocity_x(-physic.get_velocity_x());
118 //TODO: Hitpoint count incorrect when combining squishing and shooting
120 Nolok_01::kill_fall()
123 if (bullet_hitpoints <= 0) {
124 SoundManager::get()->play_sound(IDToSound(SND_FALL), this,
125 Sector::current()->player->get_pos());
126 physic.set_velocity_y(0);
127 physic.enable_gravity(true);
128 set_state(STATE_FALLING);
129 Sector::current()->add_object(new Door((int)get_pos().x+32, 512, "sector1", "main2"));
133 IMPLEMENT_FACTORY(Nolok_01, "nolok_01")