Question

I'm working on a game that is sort of like a simple Galaga-esk game. Although, they only move once in a while (something else I can't get working, but that's something different). So, since they don't move on their own, I want a way to add a timer to the game, but I can't seem to find anything on this. Here's what I have for my timer and the surrounding code to reset for each level so far. Will something like this work where I have it?

from livewires import games, color, random, time

start = time.time()
for items in enemies:
    items.destroy()
if Enemy_amount > 0:
    display_balloons()
elif Enemy_amount == 0 and (time.time() - start <= 120):
    start = time.time()
    level += 1
    Enemy_amount = load_enemies() 
    #Just telling the code to load the next group of enemies.
Was it helpful?

Solution

The value of start is going to be a number like 1398354442, which is the number of seconds that have passed since January 1, 1970.

If you want to figure out the elapsed time between two events, you'll need to subtract. Perhaps something like this?

elif Enemy_amount == 0 and (time.time() - start <= 120):
    start = time.time()   # update start variable to the current time
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top