00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "object/firefly.hpp"
00018
00019 #include <math.h>
00020
00021 #include "audio/sound_manager.hpp"
00022 #include "math/random_generator.hpp"
00023 #include "object/player.hpp"
00024 #include "object/sprite_particle.hpp"
00025 #include "supertux/game_session.hpp"
00026 #include "supertux/object_factory.hpp"
00027 #include "supertux/sector.hpp"
00028 #include "util/reader.hpp"
00029
00030 Firefly::Firefly(const Reader& lisp) :
00031 MovingSprite(lisp, "images/objects/resetpoints/default-resetpoint.sprite", LAYER_TILES, COLGROUP_TOUCHABLE),
00032 activated(false),
00033 initial_position()
00034 {
00035 initial_position = get_pos();
00036 if( !lisp.get( "sprite", sprite_name ) ){
00037 reactivate();
00038 return;
00039 }
00040 if( sprite_name == "" ){
00041 sprite_name = "images/objects/resetpoints/default-resetpoint.sprite";
00042 reactivate();
00043 return;
00044 }
00045
00046 sprite = sprite_manager->create( sprite_name );
00047 bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
00048 reactivate();
00049
00050
00051 sound_manager->preload("sounds/savebell2.wav");
00052 }
00053
00054 void
00055 Firefly::reactivate()
00056 {
00057 if(GameSession::current()->get_reset_point_pos() == initial_position){
00058
00059
00060
00061
00062
00063 sprite->set_action("ringing");
00064 }
00065 }
00066
00067 HitResponse
00068 Firefly::collision(GameObject& other, const CollisionHit& )
00069 {
00070 if(activated)
00071 return ABORT_MOVE;
00072
00073 Player* player = dynamic_cast<Player*> (&other);
00074 if(player) {
00075 activated = true;
00076
00077
00078 for (int i = 0; i < 5; i++) {
00079 Vector ppos = bbox.get_middle();
00080 float angle = graphicsRandom.randf(-M_PI_2, M_PI_2);
00081 float velocity = graphicsRandom.randf(450, 900);
00082 float vx = sin(angle)*velocity;
00083 float vy = -cos(angle)*velocity;
00084 Vector pspeed = Vector(vx, vy);
00085 Vector paccel = Vector(0, 1000);
00086 Sector::current()->add_object(new SpriteParticle("images/objects/particles/reset.sprite", "default", ppos, ANCHOR_MIDDLE, pspeed, paccel, LAYER_OBJECTS-1));
00087 }
00088
00089 sound_manager->play("sounds/savebell2.wav");
00090
00091 sprite->set_action("ringing");
00092 GameSession::current()->set_reset_point(Sector::current()->get_name(),
00093 initial_position);
00094 }
00095
00096 return ABORT_MOVE;
00097 }
00098
00099