4 #include "badguy/bouncing_snowball.h"
5 #include "badguy/snowball.h"
6 #include "badguy/mrbomb.h"
7 #include "badguy/mriceblock.h"
8 #include "badguy/mrrocket.h"
9 #include "badguy/poisonivy.h"
11 Dispenser::Dispenser(const lisp::Lisp& reader)
13 reader.get("x", start_position.x);
14 reader.get("y", start_position.y);
15 reader.get("cycle", cycle);
16 reader.get("badguy", badguy);
17 bbox.set_size(32, 32);
18 sprite = sprite_manager->create("dispenser");
19 if (badguy == "mrrocket") {
20 sprite->set_action(dir == LEFT ? "working-left" : "working-right");
22 else {sprite->set_action("dropper");}
26 Dispenser::write(lisp::Writer& writer)
28 writer.start_list("dispenser");
30 writer.write_float("x", start_position.x);
31 writer.write_float("y", start_position.y);
32 writer.write_float("cycle", cycle);
33 writer.write_string("badguy", badguy);
35 writer.end_list("dispenser");
41 dispense_timer.start(cycle, true);
46 Dispenser::collision_squished(Player& player)
48 //TODO: Should it act like a normal tile when killed?
49 sprite->set_action(dir == LEFT ? "broken-left" : "broken-right");
50 dispense_timer.start(0);
52 kill_squished(player);
57 Dispenser::active_action(float )
59 if (dispense_timer.check()) {
64 //TODO: Add launching velocity to certain badguys
65 // Add themed randomizer
66 // Fix initial direction (everyone but MrRocket walks the wrong direction)
68 Dispenser::launch_badguy()
70 //FIXME: Does is_offscreen() work right here?
71 if (!is_offscreen()) {
72 if (badguy == "snowball")
73 Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir));
74 else if (badguy == "bouncingsnowball")
75 Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir));
76 else if (badguy == "mrbomb")
77 Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir));
78 else if (badguy == "mriceblock")
79 Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir));
80 else if (badguy == "mrrocket") {
81 Sector::current()->add_object(new MrRocket(get_pos().x+(dir == LEFT ? -32 : 32), get_pos().y, dir));}
82 else if (badguy == "poisonivy")
83 Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir));
84 else if (badguy == "random")
88 case 0: Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir)); break;
89 case 1: Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir)); break;
90 case 2: Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir)); break;
91 case 3: Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir)); break;
92 case 4: Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir)); break;
98 IMPLEMENT_FACTORY(Dispenser, "dispenser")