#include <firefly.hpp>
Inherits MovingSprite.
Public Member Functions | |
Firefly (const Reader &lisp) | |
HitResponse | collision (GameObject &other, const CollisionHit &hit) |
this function is called when the object collided with any other object | |
Private Member Functions | |
void | reactivate () |
Private Attributes | |
bool | activated |
Vector | initial_position |
position as in level file. |
Definition at line 26 of file firefly.hpp.
Firefly::Firefly | ( | const Reader & | lisp | ) |
Definition at line 30 of file firefly.cpp.
References MovingObject::bbox, SpriteManager::create(), lisp::Lisp::get(), MovingObject::get_pos(), initial_position, SoundManager::preload(), reactivate(), Rectf::set_size(), sound_manager, MovingSprite::sprite, sprite_manager, and MovingSprite::sprite_name.
00030 : 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 //Replace sprite 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 //Load sound 00051 sound_manager->preload("sounds/savebell2.wav"); 00052 }
HitResponse Firefly::collision | ( | GameObject & | other, | |
const CollisionHit & | hit | |||
) | [virtual] |
this function is called when the object collided with any other object
Implements MovingObject.
Definition at line 68 of file firefly.cpp.
References ABORT_MOVE, activated, Sector::add_object(), ANCHOR_MIDDLE, MovingObject::bbox, Currenton< GameSession >::current(), Sector::current(), Rectf::get_middle(), GameObject::get_name(), graphicsRandom, initial_position, LAYER_OBJECTS, SoundManager::play(), RandomGenerator::randf(), GameSession::set_reset_point(), sound_manager, and MovingSprite::sprite.
00069 { 00070 if(activated) 00071 return ABORT_MOVE; 00072 00073 Player* player = dynamic_cast<Player*> (&other); 00074 if(player) { 00075 activated = true; 00076 // spawn some particles 00077 // TODO: provide convenience function in MovingSprite or MovingObject? 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 }
void Firefly::reactivate | ( | ) | [private] |
Definition at line 55 of file firefly.cpp.
References Currenton< GameSession >::current(), initial_position, and MovingSprite::sprite.
Referenced by Firefly().
00056 { 00057 if(GameSession::current()->get_reset_point_pos() == initial_position){ 00058 // TODO: && GameSession::current()->get_reset_point_sectorname() == <sector this firefly is in> 00059 // GameSession::current()->get_current_sector()->get_name() is not yet initialized. 00060 // Worst case a resetpoint in a different sector at the same position as the real 00061 // resetpoint the player is spawning is set to ringing, too. Until we can check the sector, too, dont set 00062 // activated = true; here. 00063 sprite->set_action("ringing"); 00064 } 00065 }
bool Firefly::activated [private] |
Vector Firefly::initial_position [private] |
position as in level file.
This is where Tux will have to respawn, as the level is reset every time
Definition at line 35 of file firefly.hpp.
Referenced by collision(), Firefly(), and reactivate().