Exemplo n.º 1
0
 /// <summary>
 /// When enemy is damaged keep hiding!
 /// </summary>
 /// <param name="sender">Sender.</param>
 /// <param name="args">Arguments.</param>
 virtual protected void EnemyDamaged(object sender, DamageInfoEventArgs args)
 {
     if (!isCharging && useChargeState && hideStateTimer > 0)
     {
         if (chargeMovement != null)
         {
             chargeMovement.SetDirection(args.DamageInfo.Direction);
         }
         isCharging     = true;
         hideStateTimer = -1.0f;
         // Turn on hurtbox
         if (characterHitBox != null && args.DamageInfo.DamageCauser is Character)
         {
             characterHitBox.Character = (Character)args.DamageInfo.DamageCauser;
             characterHitBox.GetComponent <Collider2D>().enabled = true;
         }
     }
     else
     {
         hideStateTimer = hideStateTime;
         isCharging     = false;
         // Turn off hurt box
         if (characterHitBox != null)
         {
             characterHitBox.GetComponent <Collider2D>().enabled = false;
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Init this enemy AI.
        /// </summary>
        override public void Init(Enemy enemy)
        {
            base.Init(enemy);
            // Listen to damage events and if we get them hide
            enemy.Damaged  += EnemyDamaged;
            enemy.Collided += EnemyDamaged;

            // If we need it try and find a charge movement
            if (useChargeState)
            {
                EnemyMovement_Distributor distributor = enemy.GetComponentInChildren <EnemyMovement_Distributor>();
                if (distributor != null)
                {
                    foreach (EnemyStateToMovement estm in distributor.statesToMovements)
                    {
                        if (estm.state == EnemyState.CHARGING)
                        {
                            chargeMovement = estm.movement;
                            break;
                        }
                    }
                }
                else
                {
                    chargeMovement = enemy.GetComponentInChildren <EnemyMovement_Charge>();
                }
            }
            // Try to find a cahracter hurt box so we can collect coins and damage other enemies
            characterHitBox = GetComponentInChildren <CharacterHitBox>();
            if (characterHitBox != null)
            {
                // Don't hit ourselves
                EnemyHurtBox myHurtBox = enemy.GetComponentInChildren <EnemyHurtBox>();
                if (myHurtBox != null)
                {
                    Physics2D.IgnoreCollision(characterHitBox.GetComponent <Collider2D>(), myHurtBox.GetComponent <Collider2D>());
                }
                // Init hit box
                characterHitBox.Init(new DamageInfo(1, DamageType.PHYSICAL, Vector2.zero));
            }
        }