I think theagentd’s point is that there’s no guarantee that N steps, for any integer N, will land the player on the target position, either exactly or within the epsilon margin-of-error. You’d need to choose the step length (as well as the step direction) carefully to achieve that. Or (as Karmington said) interpolate between the original position and the target position. Or do something like the following, which moves the player towards the target at a fixed speed.
static final double stepSize = 5.0; // the player's speed (how far to move each update)
double playerX, playerY; // current position
double targetX, targetY; // where the mouse click happened
// move the player one step closer to the target position
void updatePosition() {
double dx = targetX - playerX,
dy = targetY - playerY;
double distance = Math.hypot(dx,dy);
if ( distance > stepSize ) {
// still got a way to go, so take a full step
playerX += stepSize*dx/distance;
playerY += stepSize*dy/distance;
} else {
// we're either at the target already, or within one step of it
playerX = targetX;
playerY = targetY;
}
}
Simon