Пример #1
0
void Shielder::Update()
{
    fixed s = _power ? M_PT_ZERO_ONE * 12 : M_PT_ZERO_ONE * 4;
    Rotate( s );
    GetShape( 9 ).Rotate( -2 * s );
    for ( int i = 0; i < 8; i++ )
        GetShape( i ).Rotate( -s );

    bool onScreen = false;
    if ( GetPosition()._x < 0 )
        _dir.Set( 1, 0 );
    else if ( GetPosition()._x > Lib::WIDTH )
        _dir.Set( -1, 0 );
    else if ( GetPosition()._y < 0 )
        _dir.Set( 0, 1 );
    else if ( GetPosition()._y > Lib::HEIGHT )
        _dir.Set( 0, -1 );
    else
        onScreen = true;

    if ( !onScreen && _rotate ) {
        _timer = 0;
        _rotate = false;
    }

    fixed speed = SPEED + ( _power ? M_PT_ONE * 3 : M_PT_ONE * 2 ) * ( 16 - GetHP() );
    if ( _rotate ) {
        Vec2 d( _dir );
        d.Rotate( ( _rDir ? 1 : -1 ) * ( TIMER - _timer ) * M_PI / ( M_TWO * TIMER ) );
        _timer--;
        if ( _timer <= 0 ) {
            _timer = 0;
            _rotate = false;
            _dir.Rotate( ( _rDir ? 1 : -1 ) * M_PI / M_TWO );
        }
        Move( d * speed );
    }
    else {
        _timer++;
        if ( _timer > TIMER * 2 ) {
            _timer = TIMER;
            _rotate = true;
            _rDir = GetLib().RandInt( 2 ) != 0;
        }
        if ( IsOnScreen() && _timer % TIMER == TIMER / 2 && _power ) {
            Player* p = GetNearestPlayer();
            Vec2 v = GetPosition();

            Vec2 d = p->GetPosition() - v;
            d.Normalise();
            Spawn( new SBBossShot( v, d * M_THREE, 0x33cc99ff ) );
            PlaySoundRandom( Lib::SOUND_BOSS_FIRE );
        }
        Move( _dir * speed );
    }
    _dir.Normalise();

}
Пример #2
0
void Follow::Update()
{
    Rotate( M_PT_ONE );
    if ( Player::CountKilledPlayers() >= GetPlayers().size() )
        return;

    _timer++;
    if ( !_target || _timer > TIME ) {
        _target = GetNearestPlayer();
        _timer = 0;
    }
    Vec2 d = _target->GetPosition() - GetPosition();
    if ( d.Length() > 0 ) {
        d.Normalise();
        d *= SPEED;

        Move( d );
    }
}
Пример #3
0
void Tractor::Update()
{
    GetShape( 0 ).Rotate(  M_PT_ZERO_ONE * 5 );
    GetShape( 1 ).Rotate( -M_PT_ZERO_ONE * 5 );
    if ( _power ) {
        GetShape( 3 ).Rotate( -M_PT_ZERO_ONE * 8 );
        GetShape( 4 ).Rotate(  M_PT_ZERO_ONE * 8 );
    }

    if ( GetPosition()._x < 0 )
        _dir.Set( 1, 0 );
    else if ( GetPosition()._x > Lib::WIDTH )
        _dir.Set( -1, 0 );
    else if ( GetPosition()._y < 0 )
        _dir.Set( 0, 1 );
    else if ( GetPosition()._y > Lib::HEIGHT )
        _dir.Set( 0, -1 );
    else
        _timer++;

    if ( !_ready && !_spinning ) {
        Move( _dir * SPEED * ( IsOnScreen() ? M_ONE : M_TWO + M_HALF ) );

        if ( _timer > TIMER * 8 ) {
            _ready = true;
            _timer = 0;
        }
    } else if ( _ready ) {
        if ( _timer > TIMER ) {
            _ready = false;
            _spinning = true;
            _timer = 0;
            _players = GetPlayers();
            PlaySound( Lib::SOUND_BOSS_FIRE );
        }
    } else if ( _spinning ) {
        Rotate( M_PT_ONE * 3 );
        for ( unsigned int i = 0; i < _players.size(); i++ ) {
            if ( !( ( Player* )_players[ i ] )->IsKilled() ) {
                Vec2 d = GetPosition() - _players[ i ]->GetPosition();
                d.Normalise();
                _players[ i ]->Move( d * TRACTOR_SPEED );
            }
        }

        if ( _timer % ( TIMER / 2 ) == 0 && IsOnScreen() && _power ) {
            Player* p = GetNearestPlayer();
            Vec2 v = GetPosition();

            Vec2 d = p->GetPosition() - v;
            d.Normalise();
            Spawn( new SBBossShot( v, d * M_FOUR, 0xcc33ccff ) );
            PlaySoundRandom( Lib::SOUND_BOSS_FIRE );
        }

        if ( _timer > TIMER * 5 ) {
            _spinning = false;
            _timer = 0;
        }
    }
}