我正在用 PyGame 编写俄罗斯方块程序,遇到了一个有趣的问题。
在我问这个问题之前,这是伪代码:
while True:
# In this part, the human controls the block to go left, right, or speed down
if a key is pressed and the block isnt touching the floor:
if the key is K-left:
move piece left one step
if the key is K-right:
move piece right one step
if the key is K-down:
move piece down one step
# This part of the code makes the piece fall by itself
if the block isnt touching the floor:
move block down one step
# This part makes the while loop wait 0.4 seconds so that the block does not move
# down so quickly
wait 0.4 seconds
问题在于,由于代码的“等待 0.4 秒”部分,人类控制的部分只能每 0.4 秒移动一次。我希望方块移动的速度与人类按键的速度一样快,同时方块每 0.4 秒掉落一次。我如何安排代码以便它可以做到这一点?谢谢!