1

I am writing a python animation of lightning and rain with pygame. The animation of the lightning occurs every two seconds, while the animation of the rain is occurring constantly.

I am currently using the time.sleep() module to delay the lightning every, but it delays the entire program.

What would be a better way to do this?.

#Before while loop, list and variable for animating rain

list_rain=[]
for i in range(40):
    x=random.randint(400,700)
    y=random.randint(96,690)
    list_rain.append([x,y])

    q=0

#In main program loop(while loop)



#code for animating lightning
q+=5
if q <100:
    pygame.draw.polygon(screen,YELLOW,[[430,85],[410,95+q],[450,95+q]])
    if q >80:
        pygame.draw.rect(screen,YELLOW,[412,180,light_y,14])
        pygame.draw.polygon(screen,YELLOW,[[505,180],[525,180],[480,250+q]])
if light_y >100:
    light_y=0
    #why does time.sleep() affect raining?
    time.sleep(2)
    #end code for animating lightning


#start code for animating rain
for i2 in range(len(list_rain)):
    pygame.draw.circle(screen,BLUE,list_rain[i2],2)
    list_rain[i2][1]+=1
    if list_rain[i2][1]> 690:
        list_rain[i2][1]=110
    #end code for animating rain
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
Stexplore
  • 31
  • 2

0 Answers0