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()
网友评论