When I first get the theme: Reversed Role for the GMTK 2023 Game Jam, the idea of a reversed Pac Man jumped into my mind immediately. And it was a great challenge to build an intelligent enough AI to mimic the actual Pac Man player’s behaviour.
Base of the whole system:
First, to start with the base of the whole behaviour system, I choose to use A* algorithm for path finding and set up grid layout based on the tilemap, in which case to check if a tile is reachable according to the data of different layers of tilemaps. The base logic here is to have the state and target position update every time when the ghost or Pac Man reaches the centre of a grid, so that the behaviour will follow the old arcade style.
Ghosts behaviours:
For scattering state, I set up a set of stop points for each ghost and let them to patrol through them in order. And frightened state is something similar with scattering, I just add a fleeing behaviour when getting too close besides the patrolling behaviour.
For the chasing state, I choose to follow the original designed behaviour pattern as much as possible. Which you can check through the mind map above or the pictures below (thanks to this detailed article that explain the behaviour really well).
Four patterns for the ghosts (Blinky-red, Pinky-pink, Inky-cyan, Clyde-orange)
Code for Pinky's chase behaviour
Pac Man behaviours:
Basically, Pac Man’s target is simple - avoiding ghosts, eating dots as much as possible and killing ghosts when invincible. But I would like to make it arrange its path a bit wiser to avoid the ghosts. Here are my approaches of achieving that:
1. Set the two tiles ahead of each live ghost to unreachable, also the next two tiles on current ghost’s determined path.
2. Pac Man will have two targets: eating the closest dot and eating the farthest dot. Its main target will switch between this two based on its current condition.
3. There is a weight map that will tweak its path finding – dots and props in the tile will attract the Pac Man and Pac Man will avoid the tiles near the ghosts and tiles on the ghosts’ current determined path according to the those tile’s distance to the ghosts.
End words: I think the methods I took still have a lot of space to improve as it is only generated in a short time working. What I could think about currently is to have more possibility of the Pac Man's strategies. And the ghosts could have more behaviour patterns or strategy options for player to choose.
Yorumlar