The next section is going to be pretty involved, so lets take a break and do a simple small section. We simply want to display to the player how many lives they have left. We'll do that by adding some Pacman icons in the lower left corner of the screen. To do that we'll need to extract an image from the spritesheet to use as the Pacman life icon for how many lives Pacman has.
The image we're going to use to indicate the life sprite is the image at location (0, 0) in the spritesheet. At the start of the game we have 5 lives so we want to display 5 life icons. We'll just get the image 5 times and append the images in a list called self.images.
We'll import it into the run.py file and pass in the number of lives we initially have.
When Pacman loses a life, we'll remove one of the life icons.
In the render method we need to calculate where to draw the life icons. We're going to put them in the lower left corner of the screen so we need to calculate an x and y position for each icon. The y position will be the same for each of them, but x positions will start at x=0 and move towards the right as we add more life icons. When Pacman dies, a life icon will be removed.