该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
import pygame
import syspygame.init()size = width,height = 800,600
bg_color = (230,230,230)screen = pygame.display.set_mode(size)
pygame.display.set_caption("haha")images = pygame.image.load(r"D:\alien_invasion\images\ship.bmp")
image_rect = images.get_rect()
screen_image = screen.get_rect()image_rect.centerx = screen_image.centerx
image_rect.centery = screen_image.centery
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_UP and image_rect.top > screen_image.top:
image_rect.centery -= 10
screen.fill(bg_color)
screen.blit(images,image_rect)
pygame.display.flip()
elif event.type == pygame.KEYUP:
screen.fill(bg_color)
screen.blit(images,image_rect)
pygame.display.flip()
elif event.key == pygame.K_DOWN and image_rect.bottom < screen_image.bottom:
image_rect.centery += 10
elif event.key == pygame.K_RIGHT and image_rect.right < screen_image.right:
image_rect.centerx += 10
elif event.key == pygame.K_LEFT and image_rect.left > screen_image.left:
image_rect.centerx -= 10
screen.fill(bg_color)
screen.blit(images,image_rect)
pygame.display.flip()