I have a program like this. It works well bout there is a problem! By pressing the 'Down' key it shows a circle on the screen for 5 seconds and also by 'Space-down' and 'Space-up' does something else (calculates pressing time). But I don't want it to 'calculate' when is showing the circle. in the other words I don't want it to get keyboard events (or does nothing if gets keyboard events) when is showing the circle. for this purpose I added the 'p' as a condition. it somehow works! I mean during the circle show the program doesn't calculate even if you press 'Space' key. But the problem is when the circle show gets over. It does calculations just as like as you pressed the 'Space' key after circle show time. I mean if you press the 'Space' key during circle show time, it does calculations immediately after when the circle show gets over. Its like that the program gets key events even during the circle show, but waits until when the condition (p == 0 ) becomes true. Please help me to fix this situation.
p = 0
gameloop = True
while gameloop:
for event in pygame.event.get():
if (event.type == pygame.QUIT):
gameloop = False
if event.type == pygame.KEYDOWN:
if (event.key == pygame.K_DOWN) :
p += 1
start_time = time.time()
end_time = start_time + 5
while end_time > time.time():
# showing a circle on display
p -= 1
if (event.type == pygame.KEYDOWN):
if (event.key == pygame.K_SPACE) and (p == 0) :
# Do something
if (event.type == pygame.KEYUP) :
if (event.key == pygame.K_SPACE) and (p == 0) :
# Do somthing