게임을 만들고 있는데 차고에있을 때 더 많은 속도를 구입하고 이미 최대 인 경우 "최대 속도에 도달했습니다!"라는 텍스트가 팝업됩니다. 그러나 버튼을 클릭하고 최대 속도를 사용하면 유지되지 않고 1 틱 후에 사라집니다. 버튼이 작동하는 방식 때문에 더 오래 머무르게하는 방법을 알 수 없습니다. 도움을 주시면 감사하겠습니다. 버튼의 코드는 다음과 같습니다.
elif event.type == pygame.MOUSEBUTTONDOWN:
# 1 is the left mouse button, 2 is middle, 3 is right.
if event.button == 1:
# `event.pos` is the mouse position.
if button2.collidepoint(event.pos):
print('we been clicked')
current_time = time.strftime("%S")
# Increment the number
if player.vel < 20:
if player.coins >= 50:
player.vel += 5
player.coins -= 50
print('speed =' + str(player.vel))
player.vel1 = player.vel
player.grassvel = player.vel // 2
player.save()
else:
print("ur poor")
else:
MaxSpeedReached()
다음은 호출하는 함수의 코드입니다.
def MaxSpeedReached():
display_crash_text = False
print("Max speed reached")
if display_crash_text == False:
start_time = time.strftime("%S")
display_crash_text = True
maxspeedtext = pygame.font.Font("freesansbold.ttf", 20)
maxspedd, maxspeedr = text_objects("Max Speed Reached!", maxspeedtext, BLACK)
maxspeedr.center = ((205, 270))
print(current_time, start_time)
if display_crash_text == True:
win.blit(maxspedd, maxspeedr)
if int(start_time) - int(current_time) < 3:
display_crash_text = False
print("yo we checking the time difference")
MaxSpeedReached()
호출 될 때 메시지가 한 번 그려지기 때문에 분명히 이것을 볼 수 있지만이 함수에 도달 할 수있는 유일한 경로는 pygame.MOUSEBUTTONDOWN
이벤트입니다.
최대 속도 조건이 발생할 때마다 메인 루프에 메시지를 그려야합니다.
MAX_VELOCITY = 20
maxspeedtext = pygame.font.Font("freesansbold.ttf", 20)
maxspedd, maxspeedr = text_objects("Max Speed Reached!", maxspeedtext, BLACK)
maxspeedr.center = ((205, 270))
[ ... ]
# Main loop
while not finished:
[...]
if ( player.vel >= MAX_VELOCITY ):
win.blit( maxspedd, maxspeedr )
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다