python小游戏源码

见缝插针小游戏,设置关卡,难度逐渐增大,效果图如下,需要的话去个人主页提取资源

 部分代码如下:

    def __init__(self, angle):
        self.x = x0
        self.y = y0 + length
        self.center = (self.x, self.y)
        self.radius = 12
        self.angle = angle
        ball_group.append(self)

    def draw(self, surface):
        pygame.draw.line(surface, WHITE, shaft, self.center, 2)
        pygame.draw.circle(surface, WHITE, self.center, 12)

    def move(self, speed):
        """
        围绕转轴做圆周运动
        :param speed: 转动的角速度
        :return:
        """
        if self.angle < 2 * math.pi:
            self.angle += speed
        else:
            self.angle = self.angle - 2 * math.pi
        self.x = x0 - length * math.sin(self.angle)
        self.y = y0 + length * math.cos(self.angle)
        self.center = (self.x, self.y)

猜你喜欢

转载自blog.csdn.net/weixin_41217242/article/details/127145832