每当我运行此代码时,都会出现消息 pygame.error: Couldn't open ship.bmp。我将文件 ship.bmp 保存在与我的代码相同的位置。我将不胜感激任何帮助。
import sys
import pygame
pygame.init()
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width,screen_height))
bg_color = (0, 13, 114)
pygame.display.set_caption('space invaders')
shipImg = pygame.image.load("ship.bmp")
def ship(x,y):
screen.blit(shipImg, (x,y))
x = (screen_width * 0.45)
y = (screen_height * 0.8)
crashed = False
while not crashed:
#keyboard events
for event in pygame.event.get():
if event.type == pygame.QUIT:
crashed = True
screen.fill(bg_color)
ship(x,y)
pygame.display.flip()
pygame.quit()
quit()