4 #include "badguy/bouncing_snowball.h"
5 #include "badguy/snowball.h"
8 Dispenser::Dispenser(LispReader& reader)
10 reader.read_float("x", start_position.x);
11 reader.read_float("y", start_position.y);
12 reader.read_float("cycle", cycle);
13 reader.read_string("badguy", badguy);
14 bbox.set_size(32, 32);
15 sprite = sprite_manager->create("dispenser");
16 sprite->set_action("working");
20 Dispenser::write(LispWriter& writer)
22 writer.start_list("dispenser");
24 writer.write_float("x", get_pos().x);
25 writer.write_float("y", get_pos().y);
26 writer.write_float("cycle", cycle);
27 writer.write_string("badguy", badguy);
29 writer.end_list("dispenser");
35 dispense_timer.start(cycle, true);
40 Dispenser::collision_squished(Player& player)
42 //FIXME: Should act like a normal tile when killed
43 sprite->set_action("broken");
44 dispense_timer.start(0);
50 Dispenser::active_action(float )
52 if (dispense_timer.check()) {
58 Dispenser::collision_solid(GameObject& , const CollisionHit& hit)
60 if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
61 physic.set_velocity_y(0);
62 } else { // hit right or left
63 dir = dir == LEFT ? RIGHT : LEFT;
64 sprite->set_action(dir == LEFT ? "left" : "right");
65 physic.set_velocity_x(-physic.get_velocity_x());
71 //TODO: Add launching velocity to badguys
72 // Add more badguys and randomizer
73 // Clean up stuff I copied without understanding what it does :)
74 // Stop dispensing when game is paused
77 Dispenser::launch_badguy()
79 //FIXME: Does is_offscreen() work right here?
80 if (!is_offscreen()) {
81 if (badguy == "snowball")
82 Sector::current()->add_object(new SnowBall(get_pos().x-2, get_pos().y));
83 else if (badguy == "bouncingsnowball")
84 Sector::current()->add_object(new BouncingSnowball(get_pos().x-2, get_pos().y, dir));
85 else if (badguy == "random")