找回密码
 中文实名注册
搜索
查看: 254|回复: 0

水果忍者(中)

[复制链接]

23

主题

11

回帖

746

积分

高级会员

积分
746
发表于 2025-7-22 10:40:01 | 显示全部楼层 |阅读模式
            # 左半部分
            pygame.draw.circle(
                win, self.color, (center_x - 5, center_y), self.radius - 5)
            pygame.draw.circle(
                win, BLACK, (center_x - 5, center_y), self.radius - 5, 1)

            # 右半部分
            pygame.draw.circle(
                win, self.color, (center_x + 5, center_y), self.radius - 5)
            pygame.draw.circle(
                win, BLACK, (center_x + 5, center_y), self.radius - 5, 1)

            # 中间的线
            pygame.draw.line(win, BLACK,
                             (center_x - self.radius//2, center_y),
                             (center_x + self.radius//2, center_y), 2)

    def check_slice(self, start_pos, end_pos):
        if self.sliced:
            return False

        # 检查线段(鼠标轨迹)是否与圆(水果)相交
        x1, y1 = start_pos
        x2, y2 = end_pos
        x0, y0 = self.x, self.y

        # 线段向量
        dx = x2 - x1
        dy = y2 - y1

        # 线段长度的平方
        length_sq = dx*dx + dy*dy

        # 计算投影比例
        if length_sq == 0:  # 鼠标没移动
            return False

        t = ((x0 - x1)*dx + (y0 - y1)*dy) / length_sq
        t = max(0, min(1, t))  # 限制在0-1之间

        # 线段上最近的点
        closest_x = x1 + t*dx
        closest_y = y1 + t*dy

        # 计算最近点到圆心的距离
        distance = math.sqrt((closest_x - x0)**2 + (closest_y - y0) ** 2)

        return distance <= self.radius







回复

使用道具 举报

您需要登录后才可以回帖 登录 | 中文实名注册

本版积分规则

快速回复 返回顶部 返回列表