PacMan ghosts help

I am writing a PacMan program in class and can not figure out how to program the ghosts to move around the maze according to his location. This is quite a big issue, so if anyone could help, it would be great! My email is sportsboy20092000@yahoo.com if it would be easier to send me a sample code. Thanks!

Comments

re: pacman ghosts

We really shouldn't be doing your school work for you here ;-). Not sure of what you are asking--I could help with how to move objects around a confined space--maze--using the poorly (or un-) documentet readcpixel statement, but it seems that you want help determining how to direct the ghosts at your pacman. That requires a lot more info. Do you want the ghosts to actually chase the pacman or just to move in random directions? If the former, then you have to program considerable intelligence into the ghosts. They have to know where the pacman is and then have to calculate the shortest route to him--and that has to change with every movement of the pacman. There are reasons why professional programmers have full time jobs writing games! ;-)

rwt

re: pacman ghosts

Lol yes I know I wasn't meaning for you to do it for me necessarily, I just needed advice on how I might could go about writing it. I will probably just have them move in a random direction, so every time they move a space they check to see if it is a wall or open and move accordingly I guess. I used a 2-dimensional array to create the maze, so if you would like to help with an idea of how to write the syntax for this then feel free, but if not I understand, lol I'll just have to think on it for a good while. But again Thank You!

re: pacman ghosts

OK--here is a way to move objects around and detect collisions with other objects or things like the walls of your maze without the program having to know the exact nature of the maze.

Use

CALL readcpixel(x,y,red,blue,green)

You supply the x and y coordinates of one pixel of the maze wall. This will return the r,g,b settings
for that pixel in the variables red, blue, green.

Then to see if your object (ghost) has run into the wall, you check four locations--the top, bottom, right and left positions of your ghost. Say those positions are (xlghost,ylghost) (xrghost,yrghost) (xbghost,ybghost) and (xtghost,ryghost). Then you can check for a collision at each side (although if the ghost is to move left, you need only check the left, if only down, then check the bottom position, etc.

So if you want the ghost to move left such that the leftmost pixel in the ghost would be (xlghost,ylghost), do a

call readcpixel(xlghost,ylghost,rtest,gtest,btest)

BEFORE MOVING it.

If you have kept colors simple and the color of the inside of the maze does not have the same red setting as the wall, then you need only check....

If rtest = red then.....where you would probably just reverse the direction of the ghost.

This method has the advantage of being able to draw mazes and load up new ones without having to teach the computer where all the walls are.

I have a program where you move a ball through a maze using slight 'taps' where the ball will obey Newton's Laws of motion and knowledge of such can help to move the ball through quickly. I have several mazes from which to choose.

Now as to the intelligence of the ghosts--I would have them at least know if the pacman is above, below, right, or left of each ghost. I would then move the ghost in the general direction of the Pacman.

Have fun....

rwt (let me know if you need any help with smooth animations--but you'll need the TrueControls library for this--don't think it comes with the Bronze edition.)