fix warning in rocketexplosion
[supertux.git] / src / badguy / dispenser.cpp
1 #include <config.h>
2
3 #include "dispenser.h"
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
10 Dispenser::Dispenser(const lisp::Lisp& reader)
11 {
12   reader.get("x", start_position.x);
13   reader.get("y", start_position.y);
14   reader.get("cycle", cycle);
15   reader.get("badguy", badguy);
16   bbox.set_size(32, 32);
17   sprite = sprite_manager->create("dispenser");
18   sprite->set_action("working");
19 }
20
21 void
22 Dispenser::write(lisp::Writer& writer)
23 {
24   writer.start_list("dispenser");
25
26   writer.write_float("x", start_position.x);
27   writer.write_float("y", start_position.y);
28   writer.write_float("cycle", cycle);
29   writer.write_string("badguy", badguy);
30
31   writer.end_list("dispenser");
32 }
33
34 void
35 Dispenser::activate()
36 {  
37    dispense_timer.start(cycle, true);
38    launch_badguy();
39 }
40
41 bool
42 Dispenser::collision_squished(Player& player)
43 {
44   //TODO: Should it act like a normal tile when killed?
45   sprite->set_action("broken");
46   dispense_timer.start(0);
47   player.bounce(*this);
48   kill_squished(player);
49   return true;
50 }
51
52 void
53 Dispenser::active_action(float )
54 {
55   if (dispense_timer.check()) {
56     launch_badguy();
57   }
58 }
59
60 //TODO: Add launching velocity to certain badguys
61 //      Add randomizer (themed to match tileset)
62 void
63 Dispenser::launch_badguy()
64 {
65   //FIXME: Does is_offscreen() work right here?
66   if (!is_offscreen()) {
67     if (badguy == "snowball")
68       Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir));
69     else if (badguy == "bouncingsnowball")
70       Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir));
71     else if (badguy == "mrbomb")
72       Sector::current()->add_object(new MrBomb(get_pos().x, get_pos().y+32, dir));
73     else if (badguy == "mriceblock")
74       Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir));
75     else if (badguy == "mrrocket")
76       Sector::current()->add_object(new MrRocket(get_pos().x, get_pos().y+32, dir));
77     else if (badguy == "random")
78     {}
79   }
80 }
81
82 IMPLEMENT_FACTORY(Dispenser, "dispenser")