0

I'm working on a balloon pop type of game, where the player has a launcher they can move across the screen and press the left mouse button to fire missile and pop the balloons. What I want to do, is after 25 missiles are fired, move the row of balloons down using the dy property. I've gotten everything to work except for the timing of the movement. The only thing I've been able to figure out, is how to get the row to move indefinitely, but I can't get it to stop. I just want it to move for say a second. How would I do something like that? BTW, I'm using pygame, and livewires if that helps.

This is the module used to define the missile launch when the left mouse button is clicked:

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:
            a = 0
            while a < 10000000:
                SPEED = 2
                a += 1

At the moment, I tried using a huge increment counter, but that just froze the game for a couple seconds, and didn't move the balloons. So I'm basically trying to figure out a way to tell python to make SPEED equal to 2 for a certain amount of time.

emufossum13
  • 377
  • 1
  • 10
  • 21

1 Answers1

0

The problem is that nothing else will be happening in the game while your while loop is running.

One way would be to set a variable to the number of seconds you want the balloons to move.

    if CLICKS == 25:
        self.balloon_moves = 2.0 # move for 2 seconds

Then calling a move_balloons function/method from somewhere from the mainloop where you have a variable dt representing the time since the last frame

def move_baloons(self, dt):
    if self.ballon_moves <=0:
        return
    self.balloon_moves -= dt
        for b in self.balloon_list:
            b.dy += shiftamount*dt
John La Rooy
  • 295,403
  • 53
  • 369
  • 502
  • thank you for the response, I just have one question. Should i replace self.balloon_list with self.Balloons (which is the class for the actual balloon object)? – emufossum13 Jul 08 '13 at 02:07
  • No, the class describes the properties of a balloon and how it behaves. An instance of the class contains those properties. Probably you should have a list/set of instances. You may wish to refactor that method into the Balloon class `update` method if you want to be able to just call `update(dt)` on all your sprites – John La Rooy Jul 08 '13 at 02:13