예제 #1
0
    public override void Attacked(AttackType type, IAttackedable attacker = null)
    {
        if (!IsAlive)
        {
            return;
        }

        switch (type)
        {
        case AttackType.Jump:
            if (attacker != null)
            {
                attacker.Attacked(AttackType.Reflect);
            }
            break;

        case AttackType.Fire:
        case AttackType.Hit:
        case AttackType.Reflect:
        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;
        }
    }
예제 #2
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();
    }
예제 #3
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;
        }
    }
예제 #4
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();
            }
        }
    }
예제 #5
0
파일: Bullet.cs 프로젝트: dqtoy/marioNew
    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();
                }
            }
        }
    }