0

I have been trying to create a PyGame, in which the users goal is to pop as many balloons as possible in a certain time frame. Before my game gets initiated I ask the user what difficulty they would like to play on then use their input to work out a time limit. However I have struggled with getting this time limit to work. Any help would be amazing.

Cheers

2 Answers2

1

set a userevent and have it added to the event queue every 1000 ms (1 second.)

one_second_event = pygame.USEREVENT + 1

add it to the timer in init:

pygame.time.set_timer(one_second_event, 1000)

test for it in the event check

for event in pygame.event.get():
    if event.type == pygame.one_second_event:
       self.total_time += 1

you can then test total time against the time limit and quit when it is equal.

marienbad
  • 1,461
  • 1
  • 9
  • 19
1

You can do something like this :

clock = pygame.time.Clock()

#[...]
time_limit = 6000 #6000 ms
while True:
    time_limit -= clock.tick(60) #Roughly 6 seconds
    if time_limit <= 0:
        #[...] Do whatever you want here
CopyrightC
  • 857
  • 2
  • 7
  • 15