【发布时间】:2020-11-08 05:02:07
【问题描述】:
我正在用 PyGame 编写一个测试游戏,并且有一个基于回合/阶段的系统(就像在 Yu-Gi-Oh!)但是我遇到的问题是当我想增加回合计数器时(在 Draw Phases 上)它会无限期地增加它,直到我再次按下鼠标单击以释放鼠标。有没有办法打破增量并在增量一次后直接进入下一阶段? 我认为问题与游戏循环本身刷新如此之快有关。也许我可以冻结游戏循环?另一种选择是自动(不是通过鼠标点击)从一个转向转向另一个转向,但我仍然需要按下一个按钮才能进入下一个阶段。有任何想法吗?我可以在游戏循环之外增加它吗?
#The Game Phases (outside of the game loop):
phases = "Coin Flip","Your Draw Phase", "Your Standby Phase", "Your Main Phase 1", "Your Battle Phase", "Your Main Phase 2", "Your End Phase", "Their Draw Phase", "Their Standby Phase", "Their Main Phase 1", "Their Battle Phase", "Their Main Phase 2", "Their End Phase" #enemy phases
#Code Inside the game loop:
#If phase = A Draw Phase then the Turn Counter increments.
if phasecounter == 1:
turncounter += 1
elif phasecounter == 7:
turncounter += 1
#A Mouse Click that can will change the Phase on the Screen (displayed by Text).
if event.type == pygame.MOUSEBUTTONDOWN:
phasecounter += 1
#Loops the Phases.
if phasecounter > 12:
phasecounter = 1
currentphase = phases[phasecounter]
【问题讨论】:
标签: loops pygame click counter mouse