0

I'm working on a galactica type of game using pygame and livewires. However, in this game, instead of enemy's, there are balloons that you fire at. Every 25 mouse clicks, I have the balloons move down a row using the dy property set to a value of 1. If a balloon reaches the bottom, the game is over. However, I'm having some trouble figuring out how to get this to run only for, say, 1 second, or 2 seconds. Because I don't have a way to "time" the results, the dy value just indefinitely gets set to 1. Therefore, after the first 25 clicks, the row just keeps moving down. This is ok, but like I said, it's not my intended result.

Here is the code I have so far for this action:

if games.mouse.is_pressed(0):
        new_missile = missile(self.left + 6, self.top)
        games.screen.add(new_missile)
        MISSILE_WAIT = 0 #25
        CLICKS += 1
        if CLICKS == 25:
            SPEED = 1
            CLICKS = 0

CLICKS, and MISSILE_WAIT are global variables that are created and set to an initial value of 0 before this block of code. What I'm trying to figure out is the algorithim to put underneath the if CLICKS statement. I've looked through the python documentation on the time module, but just can't seem to find anything that would suit this purpose. Also, I don't think using a while loop would work here, because the computer checks those results instantly, while I need an actual timer.

emufossum13
  • 377
  • 1
  • 10
  • 21
  • You can have a timer repeat call a function. But I think what you really want is on click, which you should use the click event. Combine with pygame.time.get_ticks – ninMonkey Jul 07 '13 at 20:18
  • Essentially, I'm trying to find a way to get the sprite to move using the dy property for 1 second. I was messing around with the pygame.time functions, but couldn't get those to work either. – emufossum13 Jul 07 '13 at 21:29

1 Answers1

0

I'm not sure if I got your question but what I can suggest is that:

class Foo():
    def __init__(self):
        self.start_time = time.time()
        self.time_delay = 25 # seconds

    def my_balloon_func(self):
        if(time.time() - self.start_time) > self.time_delay:
            self.start_time = time.time()
        else:
            # do something
Vor
  • 33,215
  • 43
  • 135
  • 193