jeudi 18 octobre 2018

Pygame - Issue with Randomly Generating Sprites

I need help with randomly generating sprites.

The idea is: One head moves down the screen. Once it leaves the screen, a new random head starts moving down the screen. And so on...

I have 4 images I want to randomly select from.

My issue is: the moving "head" image is just a constant flickering cycle of all the heads in the list. The function appears to constantly blit

Here is the relevant code:

ran_head = [head1, head2, head3, head4]

def heads(img, headx, heady):
  gameDisplay.blit(img, (headx, heady))


def game_loop():
  head_width = 150
  head_height = 192
  head_startx = random.randrange(0, (display_width-150))
  head_starty = -200
  head_speed = 5

  heads(random.choice(ran_head), head_startx, head_starty)

  head_starty += head_speed

  if head_starty > display_height:
      head_starty = -200
      head_startx = random.randrange(0, (display_width-140))
      dodged += 1   #add 1 point
      head_speed += 0.5    #increase speed each time by 0.5




Aucun commentaire:

Enregistrer un commentaire