嗨,我正在为一个夏季课程做一个非常基本的游戏,我最近发现了一个不允许我同时移动和射击的错误。这是事件处理代码:
for event in pygame.event.get():
#create quit event
if event.type == QUIT:
pygame.quit()
sys.exit()
#checks for keyup events to stop movement
if event.type == KEYUP:
if event.key == pygame.K_w:
#stops player moving up
player.yVelocity += 8
if event.key == pygame.K_d:
#stops player moving right
player.xVelocity -= 8
if event.key == pygame.K_s:
#stops player moving down
player.yVelocity -= 8
if event.key == pygame.K_a:
#stops player moving left
player.xVelocity += 8
#checks for key presses
if event.type == KEYDOWN:
if event.key == pygame.K_w:
#sets variable to move player up
player.yVelocity -= 8
if event.key == pygame.K_d:
#sets variable to move player right
player.xVelocity += 8
if event.key == pygame.K_s:
#sets variable to move player down
player.yVelocity += 8
if event.key == pygame.K_a:
#sets variable to move player left
player.xVelocity -= 8
if event.key == pygame.K_ESCAPE:
#calls gameInit() to take player back to main menu
mainGame.gameInit()
#checks for clicks
if (pygame.mouse.get_pressed())[0] == 1:
#tells the game it should be firing
print("bam")
firing = True
if (pygame.mouse.get_pressed())[1] == 1:
#fires secondary ability
player.useAbility((0,0))
if (pygame.mouse.get_pressed())[0] == 0:
firing = False
if firing == True:
mainGame.bulletList = player.shoot(pygame.mouse.get_pos(), mainGame.bulletList)
对不起,如果这是一团糟,我对这一切都很新。但是,当我在检测鼠标点击的位内部放置测试打印语句时,我发现在按下某个键时不会输入鼠标。我不知道这个原因。