Firefly::Firefly(const lisp::Lisp& lisp)
: MovingSprite(lisp, "images/objects/resetpoints/default-resetpoint.sprite", LAYER_TILES, COLGROUP_TOUCHABLE), activated(false)
{
+ initial_position = get_pos();
if( !lisp.get( "sprite", sprite_name ) ){
reactivate();
return;
reactivate();
}
-void
+void
Firefly::reactivate()
{
- if(GameSession::current()->get_reset_point_pos() == get_pos()){
+ if(GameSession::current()->get_reset_point_pos() == initial_position){
// TODO: && GameSession::current()->get_reset_point_sectorname() == <sector this firefly is in>
// GameSession::current()->get_current_sector()->get_name() is not yet initialized.
// Worst case a resetpoint in a different sector at the same position as the real
activated = true;
// spawn some particles
// TODO: provide convenience function in MovingSprite or MovingObject?
- for (int i = 0; i < 5; i++) {
- Vector ppos = bbox.get_middle();
- float angle = systemRandom.randf(-M_PI_2, M_PI_2);
- float velocity = systemRandom.randf(450, 900);
- float vx = sin(angle)*velocity;
- float vy = -cos(angle)*velocity;
- Vector pspeed = Vector(vx, vy);
- Vector paccel = Vector(0, 1000);
- Sector::current()->add_object(new SpriteParticle("images/objects/particles/reset.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
- }
+ for (int i = 0; i < 5; i++) {
+ Vector ppos = bbox.get_middle();
+ float angle = systemRandom.randf(-M_PI_2, M_PI_2);
+ float velocity = systemRandom.randf(450, 900);
+ float vx = sin(angle)*velocity;
+ float vy = -cos(angle)*velocity;
+ Vector pspeed = Vector(vx, vy);
+ Vector paccel = Vector(0, 1000);
+ Sector::current()->add_object(new SpriteParticle("images/objects/particles/reset.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
+ }
// TODO play sound
sprite->set_action("ringing");
GameSession::current()->set_reset_point(Sector::current()->get_name(),
- get_pos());
+ initial_position);
}
return ABORT_MOVE;