美文网首页
12作 pygame知识

12作 pygame知识

作者: 大黄蜂人工智能 | 来源:发表于2018-09-05 09:43 被阅读0次
    
    
    import pygame
    
    if __name__ == '__main__':
    
        pygame.init()
        window = pygame.display.set_mode((400, 600))
        window.fill((255, 255, 255))
        pygame.display.flip()
    
        x = 100
        y = 100
        r = 50
    
        y_speed = 2
        x_speed = 2
    
        while True:
    
            pygame.time.delay(10)
    
            window.fill((255, 255, 255))
    
            pygame.draw.circle(window, (255, 0, 0), (x, y), r)
            pygame.display.update()
    
            y += y_speed
            x += x_speed
    
            if y > 600 - r:
                y = 600 - r
                y_speed = -4
    
            elif y<50:
                y = 50
                y_speed = 2
    
            elif x > 400 - r:
                x = 400 - r
                x_speed = -4
    
            elif x < 50:
                 x = 50
                 x_speed = 2
    
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    exit()
    

    相关文章

      网友评论

          本文标题:12作 pygame知识

          本文链接:https://www.haomeiwen.com/subject/hwiowftx.html