2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "object/firefly.hpp"
21 #include "math/random_generator.hpp"
22 #include "object/player.hpp"
23 #include "object/sprite_particle.hpp"
24 #include "supertux/game_session.hpp"
25 #include "supertux/object_factory.hpp"
26 #include "supertux/sector.hpp"
27 #include "util/reader.hpp"
29 Firefly::Firefly(const Reader& lisp) :
30 MovingSprite(lisp, "images/objects/resetpoints/default-resetpoint.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
34 initial_position = get_pos();
35 if( !lisp.get( "sprite", sprite_name ) ){
39 if( sprite_name == "" ){
40 sprite_name = "images/objects/resetpoints/default-resetpoint.sprite";
45 sprite = sprite_manager->create( sprite_name );
46 bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
53 if(GameSession::current()->get_reset_point_pos() == initial_position){
54 // TODO: && GameSession::current()->get_reset_point_sectorname() == <sector this firefly is in>
55 // GameSession::current()->get_current_sector()->get_name() is not yet initialized.
56 // Worst case a resetpoint in a different sector at the same position as the real
57 // resetpoint the player is spawning is set to ringing, too. Until we can check the sector, too, dont set
58 // activated = true; here.
59 sprite->set_action("ringing");
64 Firefly::collision(GameObject& other, const CollisionHit& )
69 Player* player = dynamic_cast<Player*> (&other);
72 // spawn some particles
73 // TODO: provide convenience function in MovingSprite or MovingObject?
74 for (int i = 0; i < 5; i++) {
75 Vector ppos = bbox.get_middle();
76 float angle = systemRandom.randf(-M_PI_2, M_PI_2);
77 float velocity = systemRandom.randf(450, 900);
78 float vx = sin(angle)*velocity;
79 float vy = -cos(angle)*velocity;
80 Vector pspeed = Vector(vx, vy);
81 Vector paccel = Vector(0, 1000);
82 Sector::current()->add_object(new SpriteParticle("images/objects/particles/reset.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
85 sprite->set_action("ringing");
86 GameSession::current()->set_reset_point(Sector::current()->get_name(),
93 IMPLEMENT_FACTORY(Firefly, "firefly");