我正在尝试在Pygame中制作游戏Space Invaders,我正在尝试显示我在绘画中制作的图像。我确实设法在显示器上获取spaceShipImage,当我想添加第二个图像时,wallImage,并添加DISPLAYSURF.blit(wallImage,(wallx,wally))我唯一看到的是wallImage而不是spaceShipImage 。所以我只能在显示器上获得1张图像。我做错了什么,如何同时显示多个图像?
import pygame, sys
from pygame.locals import *
pygame.init()
FPS = 60
fpsClock = pygame.time.Clock()
#display specs
display_width = 800
display_height = 600
#colors
black=(0,0,0)
blue=(0,0, 255)
green=(0,128,0)
red=(255,0,0)
white=(255,255,255)
yellow=(255,255,0)
#center of image
shipx = (display_width * 0.45)
shipy = (display_height * 0.8)
#movement ship is 0
shipxchange = 0
#width of spaceship
spaceshipwidth = 78
#location of the wall
wallx = 50
wally = 300
DISPLAYSURF = pygame.display.set_mode((display_width, display_height))
pygame.display.set_caption('Space Invaders')
spaceShipImage = pygame.image.load('spaceship7.png')
spaceshipRect = pygame.Rect(8,6, 71, 79) #rectangle of ship
wallImage = pygame.image.load('wall.png')
wallRect = pygame.Rect(0,0,58,17)
while True: # main game loop
DISPLAYSURF.fill(white)
DISPLAYSURF.blit(spaceShipImage, (shipx, shipy))
DISPLAYSURF.blit(wallImage, (wallx, wally))
for event in pygame.event.get():
if event.type == QUIT or (event.type == KEYUP and event.key == K_ESCAPE):
pygame.quit()
sys.exit()
if event.type == KEYDOWN and event.key == K_LEFT:
shipxchange += -5
elif event.type == KEYDOWN and event.key == K_RIGHT:
shipxchange += +5
if event.type == KEYUP and event.key == K_LEFT:
shipxchange += +5
elif event.type == KEYUP and event.key == K_RIGHT:
shipxchange += -5
shipx += shipxchange
#bounderies for the spaceship
if shipx >= display_width - spaceshipwidth:
shipx -= shipxchange
if shipx < 0:
shipx -= shipxchange
pygame.display.update()
fpsClock.tick(FPS)