Today I’m set up a ghost movement pattern. The red ghost is can moving around the map and otherwise I not make it go out of the ghost cage yet, I just make it can moving inside the ghost cage but it cannot go pass through the ghost cage door. And I also write a function that the red ghost can chasing the Pacman and when the Pacman eat the big dot, the red ghost will run away from the Pacman.
– This code is set up a ghost movement pattern.
– This is how the red ghost can moving around and otherwise is moving in the ghost cage.
– And this code is check if the ghost not dead when the Pacman power up, it will run away. If the Pacman is not power up, it will make the ghost chase the Pacman.
Above is the red ghost is chasing Pacman. In the get_targets() function, when Pacman power up and the ghosts not dead, it will replace the ghost x and y with runaway_x and runaway_y. And Pacman not power up, it will return the ghost x and y with the player position to make the ghost chasing the Pacman.
No Responses