美文网首页
2018-09-04小球运动

2018-09-04小球运动

作者: fanzl | 来源:发表于2018-09-08 17:20 被阅读0次

    1,小球随机运动

    import pygame
    from random import randint
    '''  '''
    def draw_cirtle(x,y):
        pygame.draw.circle(window, ( 255,0,255),(x,y),20)
        pygame.display.update()
    
    
    '''   '''
    pygame.init()
    window = pygame.display.set_mode((400, 600))
    window.fill((255, 255, 255))
    
    x=randint(20,580)
    y=randint(20,580)
    print(x,y)
    a=randint(-3,3)
    b=randint(-3,3)
    add_x=a
    add_y=b
    # 游戏循环
    while True:
        print(add_x,add_y)
    
        pygame.time.delay(10)
        # 将之前纸上的内容给覆盖
        window.fill((255, 255, 255))
        # 不断的画圆
        draw_cirtle(x,y)
        if (x+20)>=400:
            x=380
            add_x *= -1
        elif (x-20)<=0:
            x = 20
            add_x *= -1
        elif (y+20)==600:
            y=580
            add_y *= -1
        elif (y-20)<=0:
            y = 20
            add_y *= -1
        y+=add_y
        x+=add_x
    
        # 事件检测
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
    

    相关文章

      网友评论

          本文标题:2018-09-04小球运动

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