elif event key =k_a clickedbutton red elif event key =k_s clickedbutton green if not waitingforinput play the pattern pygame display update( pygame time wait( pattern append(random choice((yellowblueredgreen)) for button in pattern flashbuttonanimation(button pygame time wait(flashdelay waitingforinput true else wait for the player to enter buttons if clickedbutton and clickedbutton =pattern[currentstep] pushed the correct button flashbuttonanimation(clickedbutton currentstep + lastclicktime time time( if currentstep =len(pattern) pushed the last button in the pattern changebackgroundanimation( score + waitingforinput false currentstep reset back to first step elif (clickedbutton and clickedbutton !pattern[currentstep]or (currentstep ! and time time(timeout lastclicktime) pushed the incorrect buttonor has timed out gameoveranimation( reset the variables for new game pattern [ currentstep waitingforinput false score pygame time wait( changebackgroundanimation( pygame display update( fpsclock tick(fps