コード例 #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
 /// <summary>
 /// 与玩家子弹发生碰撞
 /// </summary>
 /// <param name="bullet"></param>
 /// <param name="curColliderIndex"></param>
 protected virtual void CollidedByPlayerBullet(PlayerBulletBase bullet, int curColliderIndex)
 {
     bullet.CollidedByObject(curColliderIndex);
 }