-1

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.

1 Answers1

0

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
dg99
  • 5,456
  • 3
  • 37
  • 49
  • When I added this, I also added "print start", just to see if it was working. For some reason, it shows up as numbers such as 0.0112322. Could I use something like a *.message(value,x,y) instead of this? – user3470570 Apr 24 '14 at 19:05
  • I don't know what you're referring to with `*.message(...)`, but if the value of `time.time()` is showing up as a number less than 1, there's something very wrong with your computer. Are you sure you're not printing the value of `time.time() - start`? – dg99 Apr 24 '14 at 20:25
  • Here's what I got from printing. With printing 'start', I got a huge number, which was since 1970. But printing 'time.time() - start' ended with '0.0003000209'. So, you think this has to do with my computer then? First post edited to current code. – user3470570 Apr 24 '14 at 21:22
  • So then there's no problem. That just means that the first time you're printing the elapsed time, only 300 microseconds have passed since the start of the program. That seems reasonable for a simple piece of Python code. – dg99 Apr 24 '14 at 21:27