public void HandleMove(KeyboardState keyboardState, int moveSpeed) { var vector = new Vector2(0, 0); if (keyboardState.IsKeyDown(Keys.Left)) { var intvector = new Vector2(-moveSpeed, 0); if (CanMove(intvector)) { vector += intvector; } var playerPositionOnCamera = new Vector2(Player.MapLocation.X - Camera.Location.X, Player.MapLocation.Y - Camera.Location.Y); if (playerPositionOnCamera.X < Constants.NoScrollThresholdLeft) // should we scroll the camera? { Camera.Location.X = MathHelper.Clamp(Camera.Location.X - moveSpeed, 0, (Constants.NumMapX - Constants.TilesToShowX) * Constants.SpriteWidth); } } if (keyboardState.IsKeyDown(Keys.Right)) { var intvector = new Vector2(moveSpeed, 0); if (CanMove(intvector)) { vector += intvector; } var playerPositionOnCamera = new Vector2(Player.MapLocation.X - Camera.Location.X, Player.MapLocation.Y - Camera.Location.Y); if (playerPositionOnCamera.X > Constants.NoScrollThresholdRight) // should we scroll the camera? { Camera.Location.X = MathHelper.Clamp(Camera.Location.X + moveSpeed, 0, (Constants.NumMapX - Constants.TilesToShowX) * Constants.SpriteWidth); } } if (keyboardState.IsKeyDown(Keys.Up)) { var intvector = new Vector2(0, -moveSpeed); if (CanMove(intvector)) { vector += intvector; } var playerPositionOnCamera = new Vector2(Player.MapLocation.X - Camera.Location.X, Player.MapLocation.Y - Camera.Location.Y); if (playerPositionOnCamera.Y < Constants.NoScrollThresholdTop) // should we scroll the camera? { Camera.Location.Y = MathHelper.Clamp(Camera.Location.Y - moveSpeed, 0, (Constants.NumMapY - Constants.TilesToShowY) * Constants.SpriteHeight); } } if (keyboardState.IsKeyDown(Keys.Down)) { var intvector = new Vector2(0, moveSpeed); if (CanMove(intvector)) { vector += intvector; } var playerPositionOnCamera = new Vector2(Player.MapLocation.X - Camera.Location.X, Player.MapLocation.Y - Camera.Location.Y); if (playerPositionOnCamera.Y > Constants.NoScrollThresholdBottom) // should we scroll the camera? { Camera.Location.Y = MathHelper.Clamp(Camera.Location.Y + moveSpeed, 0, (Constants.NumMapY - Constants.TilesToShowY) * Constants.SpriteHeight); } } Player.MapLocation += vector; Player.Angle = GetAngle(vector); Player.isMoving = vector != new Vector2(0, 0); var rect = new Rectangle(((int)Player.MapLocation.X + ((int)vector.X > 0 ? Constants.SpriteWidth : 0)) / Constants.SpriteWidth, ((int)Player.MapLocation.Y + ((int)vector.Y > 0 ? Constants.SpriteHeight : 0)) / Constants.SpriteHeight, 1, 1); foreach (var transition in MapTransitions) { if (transition.Exit && transition.Rectangle.Intersects(rect)) { Game1.TransitionMaps(transition); } } }