/* $Id: shieldcorona.cpp,v 1.6 2005/06/28 13:55:23 chfreund Exp $ */ #include "shieldcorona.hpp" #include "random.hpp" /**********************************************************/ #define MAX_DELAY 10 /**********************************************************/ ShieldCorona::ShieldCorona() : m_delay( 0 ) { } /**********************************************************/ ShieldCorona::~ShieldCorona() { } /**********************************************************/ void ShieldCorona::update() { // delay > 0 means that the corona is in a waiting state if( m_delay > 0 ) { // if the waiting state is finished, choose an animation sequence if( --m_delay == 0 ) { setSequence( localRnd.getUint32() % (SHIELD_CORONA_LAST_IDLE_SEQUENCE+1) ); setFrame( 0 ); } // delay <= 0 means that the corona is animated at the moment } else { // if the running animation is done if( ++m_Frame >= m_SequenceLength ) { // choose another delay m_delay = (Sint32)(localRnd.getUint32() % (MAX_DELAY+1)); setSequence( 0 ); setFrame( 0 ); } } }; /**********************************************************/ void ShieldCorona::absorbDamage( const Vector& direction ) { if( isAbsorbing() ) return; // initialize the absorbtion sequence if( direction.x >= 0 ) { if( direction.y >= 0 ) { if( direction.x < direction.y ) { setSequence( SHIELD_CORONA_LAST_IDLE_SEQUENCE + 8 ); } else { setSequence( SHIELD_CORONA_LAST_IDLE_SEQUENCE + 7 ); } } else { if( direction.x < -direction.y ) { setSequence( SHIELD_CORONA_LAST_IDLE_SEQUENCE + 5 ); } else { setSequence( SHIELD_CORONA_LAST_IDLE_SEQUENCE + 6 ); } } } else { if( direction.y >= 0 ) { if( -direction.x < direction.y ) { setSequence( SHIELD_CORONA_LAST_IDLE_SEQUENCE + 1 ); } else { setSequence( SHIELD_CORONA_LAST_IDLE_SEQUENCE + 2 ); } } else { if( direction.x < direction.y ) { setSequence( SHIELD_CORONA_LAST_IDLE_SEQUENCE + 3 ); } else { setSequence( SHIELD_CORONA_LAST_IDLE_SEQUENCE + 4 ); } } } setFrame( 0 ); // reset the delay counter in order to animate the corona // in idle mode after the absorbing sequence m_delay = 0; } /**********************************************************/ Uint32 ShieldCorona::getSerializeBufferSize() const { return NonCollidableObject::getSerializeBufferSize() + Serialize::sizeOf( m_delay ) // adds additional size for debugging (see serialize.hpp), // but only, if the tags are used PLUS_TAG_SIZE( 1 ); } /**********************************************************/ void ShieldCorona::serialize( Uint8*& bufferPointer ) const { // expands to a check of the buffer movement START_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer ); NonCollidableObject::serialize( bufferPointer ); Serialize::serialize( m_delay, bufferPointer ); // expands to tag serialization SERIALIZE_OBJECT_TAG( bufferPointer ); // expands to a check of the buffer movement END_OBJECT_SERIALIZED_SIZE_CHECK( bufferPointer, ShieldCorona ); } /**********************************************************/ void ShieldCorona::deserialize( Uint8*& bufferPointer ) { NonCollidableObject::deserialize( bufferPointer ); Serialize::deserialize( bufferPointer, m_delay ); // expands to tag deserialization DESERIALIZE_OBJECT_TAG( bufferPointer ); } /**********************************************************/