Hi, I’m doing a maze game like pacman and I’m writing the ghost class.
My question is: if I want that ghosts moves to the player direction what I’ve to do?
My solution is
a - compare the x and y values of ghosts and player
if(ghost.x > player.x) OVEST movement else EST
if(ghost.y > player.y) NORD movemente else SUD
and add this directions into preferredDir list
b - check all the possible directions of movement EST(x+1,y), OVEST(x-1,y), SUD(x,y+1), NORD(x,y-1)
and add this directions into possibleDir list
c - I compare the preferredDir list with possibleDir and
no match - i’ll choose a casual direction from possibleDir
1 match - i’ll choose this direction
2 match - i’ll choose a casual direction from preferredDir
It’s correct??