当运行以下代码行时,用户应该按“W”按钮开始冥想,然后按“S”按钮停止冥想,但是我发现,如果按下任何按钮,用户就会开始或停止冥想,这取决于DL19 =4还是0。这是个问题,因为我需要钥匙'A‘和'D’在房间中导航。对如何解决这个问题有什么建议吗?
if DL[19] == 0: # no activity
displaydata1 = font.render(" 'W' Key: meditate", True, (255,255,255))
screen.blit(displaydata1, (coordinates[0], coordinates[1] + 14))
if event.type == pygame.KEYDOWN:
if pygame.K_w:
DL[19] = 4 # set activity to meditating
elif DL[19] == 4: # meditating
displaydata1 = font.render(" 'S' Key: stop meditating", True, (255,255,255))
screen.blit(displaydata1, (coordinates[0], coordinates[1] + 14))
if event.type == pygame.KEYDOWN:
if pygame.K_s:
DL[19] = 0 # set to no activity
发布于 2022-01-10 06:18:46
if DL[19] == 0: # no activity
displaydata1 = font.render(" 'W' Key: meditate", True, (255,255,255))
screen.blit(displaydata1, (coordinates[0], coordinates[1] + 14))
if event.type == pygame.KEYDOWN:
if event.type == pygame.K_w:
DL[19] = 4 # set activity to meditating
elif DL[19] == 4: # meditating
displaydata1 = font.render(" 'S' Key: stop meditating", True, (255,255,255))
screen.blit(displaydata1, (coordinates[0], coordinates[1] + 14))
if event.type == pygame.KEYDOWN:
if event.type == pygame.K_s:
DL[19] = 0 # set to no activity
您可以使用event.type == pygame.K_w
来查看是否单击了"w“
https://stackoverflow.com/questions/70648485
复制相似问题