好的,我正在为这个学校的项目工作。我应该制作一个太空侵略者类型的游戏。我完成了使我的船移动和射击。现在是问题所在,当我尝试多火时,它会清除之前被解雇的子弹并且会触发一个新的子弹,而这根本不是一个好站点。我如何才能真正发射多个镜头?我怎样才能让我的船发射多枪?
while (running == 1):
screen.fill(white)
for event in pygame.event.get():
if (event.type == pygame.QUIT):
running = 0
elif (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_d):
dir = "R"
move = True
elif (event.key == pygame.K_a):
dir = "L"
move = True
elif (event.key == pygame.K_s):
dir = "D"
move = True
elif (event.key == pygame.K_w):
dir = "U"
move = True
elif (event.key == pygame.K_ESCAPE):
sys.exit(0)
elif (event.key == pygame.K_SPACE):
shot=True
xbul=xgun + 18
ybul=ygun
#if key[K_SPACE]:
#shot = True
if (event.type == pygame.KEYUP):
move = False
#OBJECT'S MOVEMENTS
if ((dir == "R" and xgun<460) and (move == True)):
xgun = xgun + 5
pygame.event.wait
elif ((dir == "L" and xgun>0) and (move == True)):
xgun = xgun - 5
pygame.event.wait
elif ((dir == "D" and ygun<660) and (move == True)):
ygun = ygun + 5
pygame.event.wait
elif ((dir == "U" and ygun>0) and (move == True)):
ygun = ygun - 5
screen.blit(gun, (xgun,ygun))
#PROJECTILE MOTION
#key = pygame.key.get_pressed()
if shot == True:
ybul = ybul - 10
screen.blit(bullet, (xbul, ybul))
if xbul>640:
shot=False
pygame.display.flip()
time.sleep(0.012)
你必须第一行和第二行之间的缩进错误... – mgilson
您需要保留屏幕项目符号的['list'](http://docs.python.org/3.3/tutorial/introduction.html#lists),并且移动bl它们全部在重画期间等等。 – millimoose
或Sprite的精灵组 – ninMonkey