美文网首页
2018-09-05 课后作业(day12)

2018-09-05 课后作业(day12)

作者: naruto711 | 来源:发表于2018-09-05 00:28 被阅读0次

1.让一个物体任意移动

import pygame
if __name__ == '__main__':
    pygame.init()
    window = pygame.display.set_mode((600,400))
    window.fill((255,255,255))
    pygame.display.flip()
    x = 0
    y = 0
    x_speed = 20
    y_speed = 10
    while True:
        pygame.time.delay(50)
        window.fill((255,255,255))
        pygame.draw.rect(window,(255,0,0),(x,y,100,50),0)
        pygame.display.update()
        x += x_speed
        y += y_speed
        if x > 500 or y > 350:
            x_speed,y_speed = -20,-10
        elif x < 0 or y < 0:
            x_speed,y_speed = 20,10
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()

相关文章

网友评论

      本文标题:2018-09-05 课后作业(day12)

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