小游戏

作者: Rain师兄 | 来源:发表于2021-01-02 14:30 被阅读0次

import sys,pygame

pygame.init()

size = width,height =600,400

speed = [50,50]

Black =0,0,0

screen = pygame.display.set_mode(size)

pygame.display.set_caption("Pygame壁球")

ball = pygame.image.load("球.gif")

ballrect = ball.get_rect()

while True:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            sys.exit()

    ballrect = ballrect.move(speed[0],speed[1])

    if ballrect.left <0 or ballrect.right > width:

        speed[0] = - speed[0]

    if ballrect.top <0 or ballrect.bottom > height:

        speed[1] = - speed[1]    

     screen.fill(Black)

# 将下载好的图像绘制在另一个图像上

    screen.blit(ball,ballrect)

    pygame.display.update()

相关文章

网友评论

      本文标题:小游戏

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