Esempio n. 1
0
    private IEnumerator Explosive(float time)
    {
        // Prepare explosive
        Skeleton.loop          = true;
        Skeleton.AnimationName = EnemyAnimationName.Attack;
        IsAlive = false;
        yield return(new WaitForSeconds(time));

        // Explosive
        RaycastHit2D[] hits = Physics2D.CircleCastAll(Collider.bounds.center, _radiusExplosive, Vector2.zero);
        foreach (var hit in hits)
        {
            if (hit.transform.CompareTag(ObjectTag.Player) || hit.transform.CompareTag(ObjectTag.Enemy))
            {
                IAttackedable character = hit.transform.GetComponent <IAttackedable>();
                if (character != null)
                {
                    character.Attacked(AttackType.Hit);
                }
            }
            else if (hit.transform.CompareTag(ObjectTag.TileBlock))
            {
                IGoreable g = hit.transform.GetComponent <IGoreable>();
                if (g != null)
                {
                    g.Gore();
                }
            }
        }

        Destroy();
    }
Esempio n. 2
0
    public override void Attacked(AttackType type, IAttackedable attacker = null)
    {
        if (!IsAlive && IsFreeze)
        {
            return;
        }

        switch (type)
        {
        case AttackType.Jump:
        case AttackType.Fire:
        case AttackType.Hit:
        case AttackType.Dead:
            Debug.Log("Enemy " + transform.name + " die by " + type);
            IsAlive = false;
            Die();
            break;

        case AttackType.Ice:
            Skeleton.AnimationName = EnemyAnimationName.Idle;
            Freeze();
            break;

        default:
            Debug.Log("Dont have case " + type + "");
            break;
        }
    }
Esempio n. 3
0
    public override void Attacked(AttackType type, IAttackedable attacker = null)
    {
        if (!IsAlive || IsFreeze)
        {
            return;
        }

        switch (type)
        {
        case AttackType.Jump:
        case AttackType.Fire:
        case AttackType.Hit:
        case AttackType.Reflect:
        case AttackType.Dead:
            Debug.Log("Enemy " + transform.name + " explosive by " + type);
            StartCoroutine(Explosive(_timePrepare));
            break;

        case AttackType.Ice:
            Skeleton.AnimationName = EnemyAnimationName.Idle;
            Freeze();
            break;

        default:
            Debug.Log("Dont have case " + type + "");
            break;
        }
    }
Esempio n. 4
0
 public void Attacked(AttackType type, IAttackedable attacker = null)
 {
     if (Main != null)
     {
         Main.Attacked(type, attacker);
     }
 }
Esempio n. 5
0
    public override void Attacked(AttackType type, IAttackedable attacker = null)
    {
        if (!IsAlive && IsFreeze)
        {
            return;
        }

        switch (type)
        {
        case AttackType.Jump:
            if (IsShield)
            {
                // Character was hit by player, become idle, lose shield
                Skeleton.loop          = false;
                Skeleton.AnimationName = EnemyAnimationName.Attack;
                CanMove        = false;
                _numberShield -= 1;
                Invoke("PrepareMove", 2f);
            }
            else
            {
                // Character jumped again by player, role or stop role
                CancelInvoke();
                _isRole = !_isRole;

                if (attacker != null)
                {
                    IsRight = (((ICharacter)attacker).Trans.position.x - Trans.position.x) < 0;
                }

                if (!_isRole)
                {
                    StopRole();
                }
            }
            break;

        case AttackType.Fire:
        case AttackType.Hit:
        case AttackType.Reflect:
            IsAlive = false;
            Die();
            Debug.Log("Enemy " + transform.name + " die by " + type);
            break;

        case AttackType.Ice:
            Skeleton.loop          = false;
            Skeleton.AnimationName = EnemyAnimationName.Attack;
            _isRole = false;
            StopRole();
            Freeze();
            break;

        default:
            Debug.Log("Dont have case " + type + "");
            break;
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Create damage when role
    /// </summary>
    protected void RoleDamage()
    {
        Vector2 size     = Collider.bounds.size;
        Vector2 position = Collider.bounds.center;

        size.y     *= .2f;
        size.x     *= .8f;
        position.x += IsRight ? size.x / 4 : -size.x / 4;
        RaycastHit2D[] hits = Physics2D.BoxCastAll(position, size, 0, Vector2.zero);

        bool changeDirection = false;

        foreach (var hit in hits)
        {
            if (hit.transform.CompareTag(ObjectTag.Player))
            {
                IAttackedable character = hit.transform.GetComponent <IAttackedable>();
                character.Attacked(AttackType.Reflect, this);
            }
            else if (hit.transform.CompareTag(ObjectTag.Enemy))
            {
                if (hit.transform.name == Trans.name)
                {
                    continue;
                }

                IAttackedable character = hit.transform.GetComponent <IAttackedable>();
                character.Attacked(AttackType.Reflect);
            }
            else if (hit.transform.CompareTag(ObjectTag.TileBlock))
            {
                changeDirection = true;
                IGoreable tile = hit.transform.GetComponent <IGoreable>();
                tile.Gore();
            }
            else if (hit.transform.CompareTag(ObjectTag.Ground))
            {
                changeDirection = true;
            }
        }

        if (changeDirection)
        {
            IsRight = !IsRight;
        }
    }
Esempio n. 7
0
    /// <summary>
    /// Create damage after throw
    ///  /// </summary>
    protected void CreateDamage()
    {
        RaycastHit2D[] hits = Physics2D.BoxCastAll(Col.bounds.center, Col.bounds.size, 0, Vector2.zero);
        Debug.Log("Create raycast");
        foreach (var hit in hits)
        {
            Debug.Log(hit.transform.name);
            if (hit.transform.CompareTag(ObjectTag.Enemy))
            {
                Crash();

                IAttackedable attacked = hit.transform.GetComponent <IAttackedable>();
                attacked.Attacked(AttackType.Hit);
            }
            else
            if (!(hit.transform.CompareTag(ObjectTag.Bullet) ||
                  hit.transform.CompareTag(ObjectTag.Player)))
            {
                Crash();
            }
        }
    }
Esempio n. 8
0
    public void Attacked(AttackType type, IAttackedable attacker = null)
    {
        if (!IsAlive)
        {
            return;
        }
        Debug.Log("herhe");
        switch (type)
        {
        case AttackType.Jump:
        case AttackType.Fire:
        case AttackType.Hit:
        case AttackType.Reflect:
        case AttackType.Ice:
        case AttackType.Dead:
            TakeDamage(type);
            break;

        default:
            Debug.Log("Dont have case " + type + "");
            break;
        }
    }
Esempio n. 9
0
    void DrawRaycast()
    {
        RaycastHit2D[] hits = Physics2D.CircleCastAll(_collider.bounds.center, _collider.bounds.size.x / 2 * 1.05f, Vector2.zero);
        foreach (var obj in hits)
        {
            bool isHitCharacter = false;
            if (_isPlayerFire)
            {
                isHitCharacter = obj.transform.CompareTag(ObjectTag.Enemy);
            }
            else
            {
                isHitCharacter = obj.transform.CompareTag(ObjectTag.Player);
            }

            if (isHitCharacter)
            {
                IAttackedable attacked = obj.transform.GetComponent <IAttackedable>();
                Debug.Log(obj.transform.name);
                attacked.Attacked(_type);
                DestroyBullet();
            }
            else if (!obj.transform.CompareTag(ObjectTag.Bullet) &&
                     !obj.transform.CompareTag(ObjectTag.Enemy) &&
                     !obj.transform.CompareTag(ObjectTag.Player))
            {
                if (_isPlayerFire)
                {
                    _rigid.velocity = new Vector2(_isRight ? 20f : -20f, 10f);
                }
                else
                {
                    DestroyBullet();
                }
            }
        }
    }