4 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include "dispenser.h"
24 #include "badguy/bouncing_snowball.h"
25 #include "badguy/snowball.h"
26 #include "badguy/mrbomb.h"
27 #include "badguy/mriceblock.h"
28 #include "badguy/mrrocket.h"
29 #include "badguy/poisonivy.h"
31 Dispenser::Dispenser(const lisp::Lisp& reader)
33 reader.get("x", start_position.x);
34 reader.get("y", start_position.y);
35 reader.get("cycle", cycle);
36 reader.get("badguy", badguy);
37 bbox.set_size(32, 32);
38 sprite = sprite_manager->create("dispenser");
39 if (badguy == "mrrocket") {
40 sprite->set_action(dir == LEFT ? "working-left" : "working-right");
42 else {sprite->set_action("dropper");}
46 Dispenser::write(lisp::Writer& writer)
48 writer.start_list("dispenser");
50 writer.write_float("x", start_position.x);
51 writer.write_float("y", start_position.y);
52 writer.write_float("cycle", cycle);
53 writer.write_string("badguy", badguy);
55 writer.end_list("dispenser");
61 dispense_timer.start(cycle, true);
66 Dispenser::collision_squished(Player& player)
68 //TODO: Should it act like a normal tile when killed?
69 sprite->set_action(dir == LEFT ? "broken-left" : "broken-right");
70 dispense_timer.start(0);
72 kill_squished(player);
77 Dispenser::active_action(float )
79 if (dispense_timer.check()) {
84 //TODO: Add launching velocity to certain badguys
85 // Add themed randomizer
86 // Fix initial direction (everyone but MrRocket walks the wrong direction)
88 Dispenser::launch_badguy()
90 //FIXME: Does is_offscreen() work right here?
91 if (!is_offscreen()) {
92 if (badguy == "snowball")
93 Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir));
94 else if (badguy == "bouncingsnowball")
95 Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir));
96 else if (badguy == "mrbomb")
97 Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir));
98 else if (badguy == "mriceblock")
99 Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir));
100 else if (badguy == "mrrocket") {
101 Sector::current()->add_object(new MrRocket(get_pos().x+(dir == LEFT ? -32 : 32), get_pos().y, dir));}
102 else if (badguy == "poisonivy")
103 Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir));
104 else if (badguy == "random")
108 case 0: Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir)); break;
109 case 1: Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir)); break;
110 case 2: Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir)); break;
111 case 3: Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir)); break;
112 case 4: Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir)); break;
118 IMPLEMENT_FACTORY(Dispenser, "dispenser")