Esempio n. 1
0
    private void UpdateState()
    {
        AbstractEnemyState newState = null;

        if (idleState.conditionsMet(this) && currentState.Name != idleState.Name)
        {
            newState = idleState;
        }

        if (patrolState.conditionsMet(this) && currentState.Name != patrolState.Name)
        {
            newState = patrolState;
        }

        if (chaseState.conditionsMet(this) && currentState.Name != chaseState.Name)
        {
            newState = chaseState;
        }

        if (attackState.conditionsMet(this) && currentState.Name != attackState.Name)
        {
            newState = attackState;
        }

        if (newState != null && newState != currentState)
        {
            newState.init();
            lastState    = currentState;
            currentState = newState;
        }
    }