pacman grid movement
// Detect user input and set direction
if (Keyboard.GetState().IsKeyDown(Keys.Down)) _direction = new Vector2(0, 1);
if (Keyboard.GetState().IsKeyDown(Keys.Right)) _direction = new Vector2(1, 0);
if (Keyboard.GetState().IsKeyDown(Keys.Up)) _direction = new Vector2(0, -1);
if (Keyboard.GetState().IsKeyDown(Keys.Left)) _direction = new Vector2(-1, 0);
// If there's no target and we can move in the chosen direction, set new target to be the next tile
if (_target == null)
if (CanMoveInDirection(_position, _direction))
_target = _position + _direction * 32;
// If there's a target, then move pacman towards that location, and clear target when destination is reached
if (_target != null)
if (MoveTowardsPoint(_target.Value, (float) gameTime.ElapsedGameTime.TotalSeconds))
_target = null;