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 "firefly.hpp"
23 #include "resources.hpp"
24 #include "sprite/sprite_manager.hpp"
25 #include "video/drawing_context.hpp"
27 #include "object_factory.hpp"
28 #include "game_session.hpp"
30 #include "random_generator.hpp"
31 #include "object/sprite_particle.hpp"
33 Firefly::Firefly(const lisp::Lisp& lisp)
34 : MovingSprite(lisp, "images/objects/firefly/firefly.sprite", LAYER_TILES, COLGROUP_TOUCHABLE), activated(false)
39 Firefly::write(lisp::Writer& writer)
41 writer.start_list("firefly");
42 writer.write_float("x", bbox.p1.x);
43 writer.write_float("y", bbox.p1.y);
44 writer.end_list("firefly");
48 Firefly::collision(GameObject& other, const CollisionHit& )
53 Player* player = dynamic_cast<Player*> (&other);
56 // spawn some particles
57 // TODO: provide convenience function in MovingSprite or MovingObject?
58 for (int i = 0; i < 5; i++) {
59 Vector ppos = bbox.get_middle();
60 float angle = systemRandom.randf(-M_PI_2, M_PI_2);
61 float velocity = systemRandom.randf(450, 900);
62 float vx = sin(angle)*velocity;
63 float vy = -cos(angle)*velocity;
64 Vector pspeed = Vector(vx, vy);
65 Vector paccel = Vector(0, 1000);
66 Sector::current()->add_object(new SpriteParticle("images/objects/particles/reset.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
69 sprite->set_action("ringing");
70 GameSession::current()->set_reset_point(Sector::current()->get_name(),
77 IMPLEMENT_FACTORY(Firefly, "firefly");