0

I've been suck on my Flappy Bird clone. If you don't know the game, there is an animation that happens when the bird fly up.

Here is a general idea of how I tried to do an animation: self.x and self.y refer to the position of the photo

Here is my code:

def move_up_animation(self):
    #list of bird photos to animate
    animation_list = ['1.tiff','2.tiff','3.tiff','4.tiff','5.tiff']

    for i in range(len(animation_list)):
        if self.y - 1 > 0: # checks if the bird is within the frame
            self.y = self.y - 1 #changes the bird's, allowing the bird to fly up      
            self.image = pygame.image.load(animation[i]) 
            self.display_image()

I tried time.sleep(1) but it doesn't work.

I have no idea how this code works:

 for i in range(5):
    print(i)
    time.sleep(1)
  • you can't do this with `for loop` and `time.sleep`. You have to put first image on the screen, then mainloop has to make one loop and returns to you function to put second image on screen. Then mainloop has to make another loop and return to you function to put third image on the screen, etc. – furas Jan 13 '16 at 01:15
  • 1
    don't use `time.sleep` any more. – furas Jan 13 '16 at 01:16
  • consider using making your bird a sprite. ( [sprite tutorial](http://programarcadegames.com/index.php?chapter=introduction_to_sprites) ) – cweb Jan 13 '16 at 15:28
  • Every game frame change the bird sprite to the next animation frame. – Spooky Jan 15 '16 at 22:16

1 Answers1

0

"I have no idea how this code works":

for i in range(5):
    print(i)
    time.sleep(1)"

It works like that: for will see if it's a true or false variable I on the range (0, 5), not 5. If it is true will run the print command.

time.sleep I don't know how it works.

To move the bird you need to add and decrease the y axis, for both flying and gravity. I hope you know to do do it (like pressing space it flies, no pressing it falls).

Instead of using for you can use if.

if K_SPACE:
    y -= 12

It will make the y-axis of the bird increase by 12. I hope that will be like the original jump game. To make it smooth you can use .tick() module inside the for, but I think it is really unnecessary.

gnawydna
  • 385
  • 1
  • 5
  • 22
Jean Alves
  • 78
  • 9