The ghosts in a way are simpler to animate because there are only 2 frames of animation for each direction. However, they have more animations than Pacman. When they are in FREIGHT or SPAWN modes we use different images from the spritesheet to indicate these modes. However, in those modes nothing really animates. The only animation the ghost has is it moves its eyes in the direction it is moving. Except in FREIGHT mode, where it only has a single image.
We'll start by defining some animations, like we did with Pacman.
Then in the Ghost class we'll add this line to the update method.
Alright, try the game out now and you'll see that the ghosts move around as they did before, but now they'll look in the direction that they are moving in! They also have a short 2 frame animation that is barely noticeable. Maybe try slowing down their animation or something.
Let's go ahead and add their other "animations". I added quotes there because they aren't really animations as they are just different images that we use when the ghosts are in SPAWN and FREIGHT modes.
In SPAWN mode, we use the sprites that are just their eyes. Those eyes also look in the direction they are moving in.
In FREIGHT mode, all of the ghosts turn into the blue sprite as shown. There's no animation or different sprites for the different directions. Think of it as them being dazed and confused especially since they move around randomly. When they're about to turn back to normal they will flash white for maybe a second as well.
Pacman and the ghosts look pretty good now that they have their basic animations going. We still need to program Pacman's death animation which will come later.