6/18/2023 0 Comments Red pac man ghost![]() You will see there is a special condition aboveCentre() when we check the downward movement. See figure1.py for the followPlayer() function. We could throw in another random number to choose between the two, but in testing this arrangement it doesn’t cause any significant problem with the movement. The keen-witted among you will have noticed that if x and y movements towards the player are both valid, then the y direction will always win. Then it does the same with the y coordinates. It then tests the x coordinate of the player against the x coordinate of the ghost and, if the direction is valid, sets the ghost direction to move toward the player. The followPlayer() function receives a list of directions that the ghost can move in. This calls followPlayer() if it’s the first ghost. We already have a moveGhosts() function from part one and we can add a condition to see if we are dealing with the first ghost: if g = 0: followPlayer(g, dirs). The latest version of Pygame Zero (1.2)įirst, let’s get the red ghost to follow Pac-Man.An image manipulation program such as GIMP, or images available here.We will still leave in some random movement, otherwise it may get a bit too difficult. ![]() The first we will make follow Pac-Man, and the second we will get to ambush by moving ahead of Pac-Man. We are going to add some brains to two of the ghosts. In the original game, each ghost had a program that it followed to characterise its movements. In part one, we left our ghosts wandering around the maze randomly without much thought for what they were doing, which was a bit unfair as Pac-Man could evade them without too much trouble.
0 Comments
Leave a Reply. |