Hi, I've an enemy that chase my player on maze tile game.
I've implemented the bresenham algorithm, it draw a rect from the enemy to the player, if this rect collides with a tile, enemy can't see the player and false is returned, otherwise it can see and true is returned.
The bresenham algorithm work fine, but I've a problem on my chase method:
px and py are player's coordinates
x and y are enemy's coordinates
validLocation return true if my enemy can walk in that direction:
private void chase(float px, float py)
if(x < px && validLocation(x + velocità,y))
else if(x > px && validLocation(x - velocità,y))
else if(y < py && validLocation(x,y + velocità))
else if(y > py && validLocation(x,y - velocità))
obviously this method isn't correct, for example, when I've this situation:
my ghost enemy goes to EAST, but when x > px ot goes to WEST
how I've to change the controls??
please, any suggestion??!!!!!