The idea here is that when Pacman completes a level by eating all of the pellets, then the game pauses for a few seconds and the level flashes white a few times. This is just a visual thing to let you know the level is complete.
Well, the game already pauses for a few seconds, so all we need to do is figure out how to flash the level.
If you look at the spritesheet, and then look where the maze pieces are. The last row of maze pieces shows an all-white row. This is what will allow us to flash the maze when the player wins a level.
For these changes we'll stay in the run.py file and make quite a few changes.
The reset method just resets the background to be the normal background and the timer to 0. The timer is what we are using to flash between the normal background and the flashing background.
The flash method is what we use to actually flip between the two backgrounds. We do this by setting the background object to be either the normal background or the flash background every quarter of a second.
In the startGame method make sure the setBackground() method comes after the creation of the mazeSprites object. We had it the other way around before, now we need to flip it because the setBackground method depends on it. I can probably just put that in the setBackground method as well, but it's fine.
So now we need to actually create the background flash object. We create it similarly to how we created the background object from before. It's really the same thing, we're just putting different images onto it.
We need a flashBackground boolean variable to know when we need to start flashing the background. Remember we only flash the background when the level is complete, which is when we eat all of the pellets.
Notice that I'm reseting the maze and resetting the flashBackground in several locations: whenever we start the game, start a new level, or restart a level.
In the update method we'll flash whenever the flashBackground is set to True. This becomes True in the checkPelletEvents method when Pacman eats all of the pellets.
In the render method change the self.background to self.maze.background. It's a subtle difference but a huge one.