4 #include "badguy/bouncing_snowball.h"
5 #include "badguy/snowball.h"
6 #include "badguy/mrbomb.h"
7 #include "badguy/mriceblock.h"
9 Dispenser::Dispenser(const lisp::Lisp& reader)
11 reader.get("x", start_position.x);
12 reader.get("y", start_position.y);
13 reader.get("cycle", cycle);
14 reader.get("badguy", badguy);
15 bbox.set_size(32, 32);
16 sprite = sprite_manager->create("dispenser");
17 sprite->set_action("working");
21 Dispenser::write(lisp::Writer& writer)
23 writer.start_list("dispenser");
25 writer.write_float("x", start_position.x);
26 writer.write_float("y", start_position.y);
27 writer.write_float("cycle", cycle);
28 writer.write_string("badguy", badguy);
30 writer.end_list("dispenser");
36 dispense_timer.start(cycle, true);
41 Dispenser::collision_squished(Player& player)
43 //FIXME: Should act like a normal tile when killed
44 sprite->set_action("broken");
45 dispense_timer.start(0);
51 Dispenser::active_action(float )
53 if (dispense_timer.check()) {
59 Dispenser::collision_solid(GameObject& , const CollisionHit& hit)
61 if(fabsf(hit.normal.y) > .5) { // hit floor or roof?
62 physic.set_velocity_y(0);
63 } else { // hit right or left
64 dir = dir == LEFT ? RIGHT : LEFT;
65 sprite->set_action(dir == LEFT ? "left" : "right");
66 physic.set_velocity_x(-physic.get_velocity_x());
72 //TODO: Add launching velocity to badguys
74 // Clean up stuff I copied without understanding what it does :)
75 // Stop dispensing when game is paused (timer related problem)
78 Dispenser::launch_badguy()
80 //FIXME: Does is_offscreen() work right here?
81 if (!is_offscreen()) {
82 if (badguy == "snowball")
83 Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y, dir));
84 else if (badguy == "bouncingsnowball")
85 Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y, dir));
86 else if (badguy == "mrbomb")
87 Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y, dir));
88 else if (badguy == "mriceblock")
89 Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y, dir));
90 else if (badguy == "random")