我刚刚开始使用 Pygame,到目前为止,我所有的程序都像下面的伪代码一样运行:
initialize game
while true:
for each event:
if event is close button:
close()
elif event is mouse button down:
event_handler()
logic()
draw()
update_display()
这适用于一个“框架”。但是,如果我想要一个标题屏幕(例如,单击开始)、主游戏(具有正常事件处理)和游戏结束屏幕(通过按键开始)怎么办。我决定像这样实现它:
initialize game
frame = 0
while true:
for each event:
if event is close button:
close()
if frame == 0:
if event is mouse button down:
frame = 1
elif frame == 1:
if event is mouse button down:
event_handler()
elif frame == 2:
if event is key button down:
frame = 0
if frame == 0:
frame_zero_logic()
frame_zero_draw()
elif frame == 1:
frame_one_logic()
frame_one_draw()
elif frame == 2:
frame_two_logic()
frame_two_draw()
update_display()
但是,我觉得这不是最好的实现。在 Pygame 中实现“多帧”的首选方式是什么?