This site requires JavaScript, please enable it in your browser!
Greenfoot back
Douggresham
Douggresham wrote ...

2015/4/14

Ghosts following and moving back to spawn - PacMan

Douggresham Douggresham

2015/4/14

#
I made a PacMan game about a month ago, (can be found in my scenarios) and I was wondering if there would be a simple way of getting the ghosts to follow PacMan around as he navigates the course. As it is now, the ghosts are on a set path and do not try to follow and trap the PacMan like in the actual game. The hard part about this is that the ghosts not only have to follow PacMan, but they must also navigate through the maze. Another problem to be solved is how the ghosts would move back to the spawn after they have been eaten. Right now I just have them removed from the world and added back at the spawn location after a certain amount of time. Any suggestions would be greatly appreciated.
lordhershey lordhershey

2015/4/15

#
do you want the ghosts to follow pac-man directly, or to hover around the places he has been? I will have to take a look at the code to see what strategy might be best to make ghost eyes wander back. As for the following part - the trick is not so much to follow, but to follow in such a way hat the ghost do not become totally impossible to deal with.
Douggresham Douggresham

2015/4/15

#
I suppose I would rather have the ghosts move toward his general area but not follow his path directly, otherwise they would be very easy to avoid. It needs to be movement that will somewhat corner the pac man and cut off his positions. There may not be a simple way to do exactly that. One of the idea that I have is to create intersection objects wherever there is a place that the ghost could turn. The ghost would then chose a random direction when it intersects the intersection. This would not make the ghosts move towards pac man but it would fix the problem of fixed paths.
lordhershey lordhershey

2015/4/15

#
I made a pack man clone a long time ago it is here Pac Man Clone I can get you the source code - it is not a greenfoot, but it can be wrapped up in an eclipse project or something similar. In this game the board is just a 2d array with values that say which way you can go from there. this array could be searched and I would give the ghosts a certain amount of look ahead and a factor of an amount of randomness they had to suffer. As the levels go up the length factor goes up and the randomness factor goes down. I also had it so the ghost do not like to plan over each others paths, this kept them from clumping and thus much more likely to pick paths to surround the player. For yours since you do not have this rigid structure - I think you could use a series of like heat or scent bubbles the get a high value when pac man was just there, and the strength drops off, the ghosts could look for these bubbles and the direction it would pick would be the warmer direction. Make 2 ghost select the warmest directions, and the third picks the second best and the fourth the third best. That is what I would try I think. I would make the heat bubble invisible, but use colored ones for debugging, though it would be amusing to see a gassy pack man. :D
Douggresham Douggresham

2015/4/19

#
Yeah I would love to see the source code for that. I think I'll try what you said to do with the bubbles that PacMan could drop. That sounds like a pretty good idea.
You need to login to post a reply.