4 // Copyright (C) 2006 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 02111-1307, USA.
22 #include "dispenser.hpp"
23 #include "badguy/bouncing_snowball.hpp"
24 #include "badguy/snowball.hpp"
25 #include "badguy/mrbomb.hpp"
26 #include "badguy/mriceblock.hpp"
27 #include "badguy/mrrocket.hpp"
28 #include "badguy/poisonivy.hpp"
29 #include "badguy/snail.hpp"
30 #include "badguy/skullyhop.hpp"
31 #include "random_generator.hpp"
33 Dispenser::Dispenser(const lisp::Lisp& reader)
34 : BadGuy(reader, "images/creatures/dispenser/dispenser.sprite")
36 reader.get("cycle", cycle);
37 reader.get("badguy", badguy);
38 if (badguy == "mrrocket") {
39 sprite->set_action(dir == LEFT ? "working-left" : "working-right");
41 else {sprite->set_action("dropper");}
42 bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
47 Dispenser::write(lisp::Writer& writer)
49 writer.start_list("dispenser");
51 writer.write_float("x", start_position.x);
52 writer.write_float("y", start_position.y);
53 writer.write_float("cycle", cycle);
54 writer.write_string("badguy", badguy);
56 writer.end_list("dispenser");
62 dispense_timer.start(cycle, true);
67 Dispenser::collision_squished(Player& player)
69 //TODO: Should it act like a normal tile when killed?
70 sprite->set_action(dir == LEFT ? "broken-left" : "broken-right");
71 dispense_timer.start(0);
73 kill_squished(player);
78 Dispenser::active_update(float )
80 if (dispense_timer.check()) {
85 //TODO: Add launching velocity to certain badguys
86 // Add themed randomizer
87 // Fix initial direction (everyone but MrRocket walks the wrong direction)
89 Dispenser::launch_badguy()
91 //FIXME: Does is_offscreen() work right here?
92 if (!is_offscreen()) {
93 if (badguy == "snowball")
94 Sector::current()->add_object(new SnowBall(Vector(get_pos().x, get_pos().y+32), dir));
95 else if (badguy == "bouncingsnowball")
96 Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x, get_pos().y+32), dir));
97 else if (badguy == "mrbomb")
98 Sector::current()->add_object(new MrBomb(Vector(get_pos().x, get_pos().y+32), dir));
99 else if (badguy == "mriceblock")
100 Sector::current()->add_object(new MrIceBlock(Vector(get_pos().x, get_pos().y+32), dir));
101 else if (badguy == "snail")
102 Sector::current()->add_object(new Snail(Vector(get_pos().x, get_pos().y+32), dir));
103 else if (badguy == "mrrocket") {
104 Sector::current()->add_object(new MrRocket(Vector(get_pos().x+(dir == LEFT ? -32 : 32), get_pos().y), dir));}
105 else if (badguy == "poisonivy")
106 Sector::current()->add_object(new PoisonIvy(Vector(get_pos().x, get_pos().y+32), dir));
107 else if (badguy == "skullyhop")
108 Sector::current()->add_object(new SkullyHop(Vector(get_pos().x, get_pos().y+44), dir));
109 else if (badguy == "random")
111 switch (systemRandom.rand(7))
113 case 0: Sector::current()->add_object(new SnowBall(Vector(get_pos().x, get_pos().y+32), dir)); break;
114 case 1: Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x, get_pos().y+32), dir)); break;
115 case 2: Sector::current()->add_object(new MrBomb(Vector(get_pos().x, get_pos().y+32), dir)); break;
116 case 3: Sector::current()->add_object(new MrIceBlock(Vector(get_pos().x, get_pos().y+32), dir)); break;
117 case 4: Sector::current()->add_object(new PoisonIvy(Vector(get_pos().x, get_pos().y+32), dir)); break;
118 case 5: Sector::current()->add_object(new Snail(Vector(get_pos().x, get_pos().y+32), dir)); break;
119 case 6: Sector::current()->add_object(new SkullyHop(Vector(get_pos().x, get_pos().y+44), dir)); break;
125 IMPLEMENT_FACTORY(Dispenser, "dispenser")