// Alot of the time it will be sensible to have the same object/component implementing both the characters perception management (awareness state)
    // and the perception event invoker, because the thing managing what the character is aware of is the best position to know when to invoke certain
    // events relating to those very perceptions. However, those things are still logically distinct in regard to the USERS of those operations, namely,
    // some clients will care about controlling the parameters of the awareness logic, while others will only care about recieving updates on what the
    // character is currently awareof/percieving. Consequently, these are two distinct interfaces!

    // Use unity engine to aquire all the dependencies needed for a character to operate. They are mandated by this script to be attached to the gameobject.
    void Awake()
    {
        object[] temp = GetComponents <ICombatAi>();
        if (temp.Length > 1)
        {
            throw new System.Exception("Character gameobject had more than one ICombatAi component attached! This is not allowed");
        }
        combatAi = (ICombatAi)temp[0];

        temp = GetComponents <IHealthSystem>();
        if (temp.Length > 1)
        {
            throw new System.Exception("Character gameobject had more than one IHealthSystem component attached! This is not allowed");
        }
        healthSystem = (IHealthSystem)temp[0];

        temp = GetComponents <IPerceptionEventInvoker>();
        if (temp.Length > 1)
        {
            throw new System.Exception("Character gameobject had more than one IPerceptionEventInvoker component attached! This is not allowed");
        }
        perceptionEventInvoker = (IPerceptionEventInvoker)temp[0];

        temp = GetComponents <ICharacterAwarenessState>();
        if (temp.Length > 1)
        {
            throw new System.Exception("Character gameobject had more than one ICharacterAwarenessState component attached! This is not allowed");
        }
        characterAwarenessState = (ICharacterAwarenessState)temp[0];
    }
Example #2
0
 private void HandleEnemyWaveDeath(IHealthSystem enemyHealth)
 {
     if (enemyHealth.IsPermaDead)
     {
         StartCoroutine(nameof(SlowAndWin));
     }
     else
     {
         StartCoroutine(nameof(LoadNextWave));
     }
 }
        private void Awake( )
        {
            gameStateController = GameStateController.GetSingletonInstance( );
            wordFileReader      = WordFileController.GetSingletonInstance( );
            healthController    = HealthController.GetSingletonInstance( );
            healthController.InitializeHealth( );

            textManager = GameObject.Find("TextAnchor").GetComponent <TextManager> ( );
            textManager.HealthUpdate(healthController.GetHealth( ));

            inputManager = gameObject.GetComponent <InputManager> ( );
            levelManager = gameObject.GetComponent <LevelManager> ( );
        }
Example #4
0
 private void Awake()
 {
     _camera                    = Camera.main;
     _rigidbody                 = GetComponent <Rigidbody2D>();
     _playerHealth              = GetComponent <IHealthSystem>();
     _playerHealth.OnWaveDeath += playerHealth =>
     {
         AudioClipPlayer.PlayAudioAtLocation(deathClip, transform.position);
         if (playerHealth.IsPermaDead)
         {
             StartCoroutine(nameof(SlowAndDeath));
         }
     };
 }
Example #5
0
    private void Awake()
    {
        bossCamera.SetActive(false);

        IHealthSystem enemyHealthSystem = GameObject.FindWithTag("Enemy")?.GetComponent <IHealthSystem>();

        if (enemyHealthSystem != null)
        {
            enemyHealthSystem.OnWaveDeath += enemyHealth =>
            {
                if (!enemyHealth.IsPermaDead)
                {
                    StartCoroutine(nameof(TempSwitchToBossCam));
                }
            };
        }
    }
Example #6
0
    private void Start()
    {
        IHealthSystem playerHealth = GameObject.FindWithTag("Player")?.GetComponent <IHealthSystem>();
        IHealthSystem enemyHealth  = GameObject.FindWithTag("Enemy")?.GetComponent <IHealthSystem>();

        if (playerHealth == null)
        {
            StopAndThrowInitializationError($"MainUI could not locate Player's {nameof(IHealthSystem)} component");
        }

        if (enemyHealth == null)
        {
            StopAndThrowInitializationError($"MainUI could not locate Enemy's {nameof(IHealthSystem)} component");
        }

        playerHealth.OnHealthChange += heath => { _playerHealthSlider.value = heath.HealthPercentage; };
        enemyHealth.OnHealthChange  += heath => { _enemyHealthSlider.value = heath.HealthPercentage; };
    }
Example #7
0
    private void Awake()
    {
        _rigidbody2D = GetComponent <Rigidbody2D>();
        _transform   = transform;


        IHealthSystem playerHealth = GameObject.FindWithTag("Player")?.GetComponent <IHealthSystem>();
        IHealthSystem enemyHealth  = GameObject.FindWithTag("Enemy")?.GetComponent <IHealthSystem>();

        if (playerHealth != null)
        {
            playerHealth.OnWaveDeath += _ => _isDisabled = true;
        }

        if (enemyHealth != null)
        {
            enemyHealth.OnWaveDeath += _ => _isDisabled = true;
        }
    }
Example #8
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        string otherColliderTag = other.gameObject.tag;

        if ("Wall" == otherColliderTag)
        {
            Destroy(gameObject);
            AudioClipPlayer.PlayAudioAtLocation(soundWall, _transform.position, 0.5f);
            return;
        }

        if (_isDisabled)
        {
            return;
        }

        switch (otherColliderTag)
        {
        case "Player":
        case "Enemy":
            IHealthSystem otherHealthSystem = other.GetComponent <IHealthSystem>();
            otherHealthSystem.DealDamage(damage);
            Destroy(gameObject);
            AudioClipPlayer.PlayAudioAtLocation(soundDamage, _transform.position);
            break;

        case "Mirror" when canBeDeflected:
            Transform mirrorTransform = other.transform;
            if (IsProjectileCollidingWithFrontOfMirror(mirrorTransform, _transform.position))
            {
                Vector2 reflectionVector = Vector2.Reflect(transform.right, mirrorTransform.right);
                _transform.right      = reflectionVector.normalized;
                _rigidbody2D.velocity = Vector2.zero;
                _rigidbody2D.AddForce(LaunchVector);
                DelayCollisions();
                AudioClipPlayer.PlayAudioAtLocation(soundReflection, _transform.position, 0.5f);
            }
            break;
        }
    }
Example #9
0
 private void Awake()
 {
     healthSystem = (IHealthSystem)transform.parent.gameObject.GetComponent <MonoBehaviour>();
 }