import pygame
import sys
def run_game():
pygame.init()
screen=pygame.display.set_mode((1200,600))
pygame.display.set_caption("game over")
image=pygame.image.load('selfimages/airplane.bmp')
rect=image.get_rect()
screen_rect=screen.get_rect()
rect.centerx=screen_rect.centerx
rect.centery=screen_rect.centery
xcenter=float(rect.centerx)
ycenter=float(rect.centery)
moving_right=False
moving_left=False
moving_down=False
moving_up=False
while True:
for event in pygame.event.get():
if event.type==pygame.QUIT:
sys.exit()
elif event.type==pygame.KEYDOWN:
if event.key==pygame.K_RIGHT:
moving_right=True
elif event.key==pygame.K_LEFT:
moving_left=True
elif event.key==pygame.K_UP:
moving_up=True
elif event.key==pygame.K_DOWN:
moving_dowm=True
elif event.type==pygame.KEYUP:
if event.key==pygame.K_RIGHT:
moving_right=False
elif event.key==pygame.K_LEFT:
moving_left=False
elif event.key==pygame.K_UP:
moving_up=False
elif event.key==pygame.K_DOWN:
moving_dowm=False
if moving_right and rect.right<screen_rect.right:
xcenter+=1.5
if moving_left and rect.left>0:
xcenter-=1.5
if moving_up and rect.top<screen_rect.top:
ycenter+=1.5
if moving_down and rect.bottom>0:
ycenter-=1.5
rect.centerx=xcenter
rect.centery=ycenter
screen.fill((255,255,255))
screen.blit(image,rect)
pygame.display.flip()
run_game()
麻烦帮我看看问题出在哪,谢谢大家