Exemplo n.º 1
0
    protected override void Update()
    {
        base.Update();

        // Update animator values.
        _anim.SetFloat("Health", _bossHealth);
        _anim.SetBool("FacingLeft", facingLeft);

        // Wear out the rage meter as time goes by.
        rageMeter -= Time.deltaTime;
        if (enraged && rageMeter < rageMax)
        {
            enraged = false;
        }

        // Knight must stay in the level boundaries.
        this.transform.position = LevelBoundary.adjustPositionToBoundary(this.transform.position);
    }
Exemplo n.º 2
0
    protected virtual void Update()
    {
        base.Update();

        // Move enemy based on force.
        _controller.Move(new Vector3(xForce, yForce, 0));
        if (xForce > friction)
        {
            xForce -= friction;
        }
        else if (xForce < -friction)
        {
            xForce += friction;
        }
        else if (xForce != 0)
        {
            xForce = 0;
        }
        if (yForce > friction)
        {
            yForce -= friction;
        }
        else if (yForce < -friction)
        {
            yForce += friction;
        }
        else if (yForce != 0)
        {
            yForce = 0;
        }

        switch (state)
        {
        case EnemyStates.spawn:
            break;

        case EnemyStates.move:
            MoveToPlayer();
            CheckToAttack();
            break;

        case EnemyStates.stand:
            CheckToAttack();
            break;

        case EnemyStates.attack:
            // Enemy animates, but otherwise doesn't do anything. The animation state will call for change.
            break;

        case EnemyStates.shoot:
            // Enemy animates, but otherwise doesn't do anything. The animation state will call for change.
            break;

        case EnemyStates.paceBack:
        case EnemyStates.paceForth:
            MoveToTarget(_paceTarget);
            CheckToAttack();
            break;

        case EnemyStates.stun:
            break;

        case EnemyStates.dead:
            break;
        }

        // Tick down the cooldowns.
        if (_attackCooldown > 0)
        {
            _attackCooldown -= Time.deltaTime;
            if (_attackCooldown < 0)
            {
                _attackCooldown = 0;
            }
        }
        if (_gunCooldown > 0)
        {
            _gunCooldown -= Time.deltaTime;
            if (_gunCooldown < 0)
            {
                _gunCooldown = 0;
            }
        }

        if (_paceTimer > 0)
        {
            _paceTimer -= Time.deltaTime;
            if (_paceTimer < 0)
            {
                if (state == EnemyStates.paceBack)
                {
                    setState(EnemyStates.paceForth);
                }
                else if (state == EnemyStates.paceForth)
                {
                    setState(EnemyStates.paceBack);
                }
            }
        }

        if (_anim != null)
        {
            _anim.SetFloat("Health", _enemHealth);
            _anim.SetBool("FacingLeft", facingLeft);
            _anim.SetInteger("PlayerHealth", _playerControl.playerHealth);
        }

        // Confine the enemy to the level boundaries.
        if (state != EnemyStates.dead)
        {
            this.transform.position = LevelBoundary.adjustPositionToBoundary(this.transform.position);
        }

        if (_useRage && _rageLevel > 0)
        {
            // Rage meter ticks down fast. Otherwise it's a second per damage point; way too long.
            _rageLevel -= Time.deltaTime * rageDecayPerSec;
            rageMeter.setDirection(facingLeft);
            rageMeter.subtractRageLevel(Time.deltaTime * rageDecayPerSec);
            if (_enraged && _rageLevel <= 0)
            {
                _enraged = false;
            }
        }
    }