2 回答
TA贡献1860条经验 获得超8个赞
我终于找到了如何让它工作。这可能不是最好的解决方案,但它完全符合我的要求。相反,或者只有if keys[pygame.K_UP]and if keys[pygame.K_LEFT],我这样写:
if keys[pygame.K_UP] and not keys[pygame.K_LEFT]:
...
if keys[pygame.K_LEFT] and not keys[pygame.K_UP]:
...
if keys[pygame.K_LEFT] and keys[pygame.K_UP]:
...
所以它知道我当时按下了两个键。感谢那些试图帮助我的人!
TA贡献1829条经验 获得超9个赞
根据评论讨论,这段代码应该可以工作。首先检查是否按下了两个键,然后检查是否按下了各个键。
keys = pg.key.get_pressed()
if (keys[pg.K_LEFT] or keys[pg.K_q]) and (keys[pg.K_UP] or keys[pg.K_z]):
van.state = VAN_LEFT_UP
screen.acceleration.x = screen.vitesse
screen.acceleration.y = screen.vitesse
elif keys[pg.K_LEFT] or keys[pg.K_q]:
van.state = VAN_LEFT
screen.acceleration.x = screen.vitesse
elif keys[pg.K_UP] or keys[pg.K_z]:
van.state = VAN_UP
screen.acceleration.y = screen.vitesse
添加回答
举报