コード例 #1
0
    private bool DetectCollisionWithPlayerBullet(PlayerBulletBase bullet)
    {
        int  nextColliderIndex = 0;
        int  curColliderIndex;
        bool isCollided = false;

        do
        {
            CollisionDetectParas collParas = bullet.GetCollisionDetectParas(nextColliderIndex);
            curColliderIndex  = nextColliderIndex;
            nextColliderIndex = collParas.nextIndex;
            if (collParas.type == CollisionDetectType.Circle)
            {
                // 子弹为圆形判定,先检测外切正方形
                float dx = Mathf.Abs(_curPos.x - collParas.centerPos.x);
                float dy = Mathf.Abs(_curPos.y - collParas.centerPos.y);
                // 两圆的半径和
                float sumOfRadius = _radius + collParas.radius;
                if (dx <= sumOfRadius && dy <= sumOfRadius)
                {
                    if (dx * dx + dy * dy <= sumOfRadius * sumOfRadius)
                    {
                        bullet.CollidedByObject(curColliderIndex);
                        isCollided = true;
                    }
                }
            }
        } while (nextColliderIndex != -1);
        return(isCollided);
    }
コード例 #2
0
    private bool DetectCollisionWithPlayerBullet(PlayerBulletBase bullet)
    {
        int  nextColliderIndex = 0;
        int  curColliderIndex;
        bool isCollided = false;

        do
        {
            CollisionDetectParas collParas = bullet.GetCollisionDetectParas(nextColliderIndex);
            curColliderIndex  = nextColliderIndex;
            nextColliderIndex = collParas.nextIndex;
            if (collParas.type == CollisionDetectType.Circle)
            {
                // 子弹为圆形判定,方形判定来检测
                float dx = Mathf.Abs(_curPos.x - collParas.centerPos.x);
                float dy = Mathf.Abs(_curPos.y - collParas.centerPos.y);
                // 检测该碰撞矩形与方形是否相交
                if (dx <= _halfWidth + collParas.radius && dy <= _halfHeight + collParas.radius)
                {
                    CollidedByPlayerBullet(bullet, curColliderIndex);
                    isCollided = true;
                }
            }
        } while (nextColliderIndex != -1);
        return(isCollided);
    }
コード例 #3
0
 public bool RegisterPlayerBullet(PlayerBulletBase bullet)
 {
     if (bullet == null)
     {
         return(false);
     }
     _playerBullets.Add(bullet);
     _playerBulletsCount++;
     _countOfPlayerBulletCreatedInFrame++;
     return(true);
 }
コード例 #4
0
        private void ShotBullet(PlayerBulletBase bullet)
        {
            var front = GetPlayerShipFront();

            //自機の回転からQuaternionを取得
            var playerTransform  = transform;
            var playerQuaternion = Quaternion.Euler(playerTransform.eulerAngles);
            var offsetResult     = playerQuaternion * bulletSpawnOffset;

            var p = playerTransform.position + (front * Time.deltaTime) + offsetResult;
            var r = playerTransform.rotation;

            bullet.SpawnBullet(p, r);
        }
コード例 #5
0
    public bool GetFreeBullet(out PlayerBulletBase bullet)
    {
        //Debug.Log("TryGet");
        foreach (var b in poolBullets)
        {
            if (b.gameObject.activeSelf)
            {
                continue;
            }
            bullet = b;
            return(true);
        }

        bullet = null;
        return(false);
    }
コード例 #6
0
    private bool DetectCollisionWithPlayerBullet(PlayerBulletBase bullet)
    {
        int  nextColliderIndex = 0;
        int  curColliderIndex;
        bool isCollided = false;

        do
        {
            CollisionDetectParas collParas = bullet.GetCollisionDetectParas(nextColliderIndex);
            curColliderIndex  = nextColliderIndex;
            nextColliderIndex = collParas.nextIndex;
            if (collParas.type == CollisionDetectType.Circle)
            {
                if (MathUtil.DetectCollisionBetweenCircleAndOBB(collParas.centerPos, collParas.radius, _curPos, _halfWidth, _halfHeight, _curRotation))
                {
                    CollidedByPlayerBullet(bullet, curColliderIndex);
                    isCollided = true;
                }
            }
        } while (nextColliderIndex != -1);
        return(isCollided);
    }
コード例 #7
0
 /// <summary>
 /// 与玩家子弹发生碰撞
 /// </summary>
 /// <param name="bullet"></param>
 /// <param name="curColliderIndex"></param>
 protected virtual void CollidedByPlayerBullet(PlayerBulletBase bullet, int curColliderIndex)
 {
     bullet.CollidedByObject(curColliderIndex);
 }