Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Ghost pathfinding for Pacman help please.  (Read 7375 times)

0 Members and 1 Guest are viewing this topic.

Mr Random

  • Newbie
  • *
  • Posts: 4
    • View Profile
Ghost pathfinding for Pacman help please.
« on: August 09, 2011, 03:44:32 am »
Hi guys I've been making a simple game of pacman. Currently I have the map, Pac-pills, Pac-man, Movement and Powerpills in the game all working as intended.

I'm trying to implement my first ghost and get him fully working before worrying about the others

I really need help making my ghost chase Pacman, After some research I'd like to use Dijkstra's algorithm and nodes but I cant figure out how to implement these into pacman.

I've found several tutorials that show how to use the algorithm, finding a path between 3 or 4 nodes.
 
The main things I'm having problems with is giving a node a position in my map, how to make the ghost move according to the nodes positions and how to detect which node is closest to the player.

Any help would be appreciated.

SCPM

  • Newbie
  • *
  • Posts: 11
    • View Profile
Ghost pathfinding for Pacman help please.
« Reply #1 on: August 09, 2011, 07:51:14 pm »
There is a detailed and informative article here on Pac-Man ghost behavior:
http://gameinternals.com/post/2072558330/understanding-pac-man-ghost-behavior
You can create a grid like the one in the article by making a two-dimensional integer array of 1s and 0s, where 1s are tiles that the actors cannot move to.  So, for example to get the tile Pac-Man is currently at, you get the integer value of Pac-Man's center x in global coordinates divided by how many pixels wide one grid square is, and the integer value of Pac-Man's center y in global coordinates divided by how many pixels tall one grid square is (so if Pac-Man is at 65, 73 on a grid of 8x8 squares means Pac-Man is at square 8,9).  Then you pass this coordinate to the ghost's pathfinding function.
But, why not use A* pathfinding?
Dijikstra's algorithm is unnecessarily complex for a Pac-Man type of game, in my opinion.  Just look at this comparison:
http://theory.stanford.edu/~amitp/GameProgramming/AStarComparison.html#S3

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Ghost pathfinding for Pacman help please.
« Reply #2 on: August 09, 2011, 08:27:08 pm »
By the way, the A* and Dijkstra algorithms are already implemented in Boost.Graph. Just in case you don't want to reinvent the wheel. ;)
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Mr Random

  • Newbie
  • *
  • Posts: 4
    • View Profile
Ghost pathfinding for Pacman help please.
« Reply #3 on: August 10, 2011, 02:41:44 am »
Thanks for the help guys.

I'm having 1 more issue with my pacman game which is probably easy to solve and im just missing the obvious.

Im trying to get the ghosts to move between two nodes smoothly. Is there a move to command or something i can easily do this with?

Also where can i read more on Boost.Graph? that sounds very interesting

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Ghost pathfinding for Pacman help please.
« Reply #4 on: August 10, 2011, 02:10:04 pm »
Quote from: "Mr Random"
Im trying to get the ghosts to move between two nodes smoothly. Is there a move to command or something i can easily do this with?
Change the ghost's position only by a small offset...

Quote from: "Mr Random"
Also where can i read more on Boost.Graph? that sounds very interesting
Google "Boost Graph" -> first link ;)

Boost is a collection of many useful C++ libraries. It may appear complicated when you haven't worked with it yet, but in general, its features are extremely generic and flexible.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

gl0w

  • Newbie
  • *
  • Posts: 20
    • View Profile
Re: Ghost pathfinding for Pacman help please.
« Reply #5 on: August 10, 2011, 10:47:22 pm »
Quote from: "Mr Random"
Hi guys I've been making a simple game of pacman. Currently I have the map, Pac-pills, Pac-man, Movement and Powerpills in the game all working as intended.

I'm trying to implement my first ghost and get him fully working before worrying about the others

I really need help making my ghost chase Pacman, After some research I'd like to use Dijkstra's algorithm and nodes but I cant figure out how to implement these into pacman.

I've found several tutorials that show how to use the algorithm, finding a path between 3 or 4 nodes.
 
The main things I'm having problems with is giving a node a position in my map, how to make the ghost move according to the nodes positions and how to detect which node is closest to the player.

Any help would be appreciated.


Hii,

I'm trying to make a pacman game aswell, and i'm getting difficult making the map, and let or not the pacman hit the walls. Could you please share your code? i'm using an array representing my screen. And i have 1, and 0 on the array, 1 represents a wall...

Any help would be appreciated.

thank you!!

 

anything