/// <summary> /// Calculates what square contains the position /// </summary> /// <param name="position"></param> /// <param name="gridLayout"></param> /// <returns>Square containing the point</returns> public Point?SquareContains(Vector2 position, GridLayout gridLayout) { // Return null if position is outside of play area if (!gridLayout.CalculatePlayArea(sizeX, sizeY).Contains(position)) { return(null); } // Remove position offset position -= gridLayout.Position; // Calculate which square int squareX = (int)(position.X / gridLayout.SquareSize); int squareY = (int)(position.Y / gridLayout.SquareSize); return(new Point(squareX, squareY)); }
protected void ConfigureCamera() { camera = new Camera2D(this) { Origin = Vector2.Zero }; playArea = gridLayout.CalculatePlayArea(grid.sizeX, grid.sizeY); // Get screen size Point screenSize = new Point(graphics.GraphicsDevice.DisplayMode.Width, graphics.GraphicsDevice.DisplayMode.Height); // Set initial window size graphics.PreferredBackBufferWidth = screenSize.X - ConsoleManager.ConsoleWindow.Right - 8; graphics.PreferredBackBufferHeight = screenSize.Y; graphics.ApplyChanges(); // Zoom if (playArea.Width > playArea.Height) { camera.ZoomToMatchWidth(playArea); } else { camera.ZoomToMatchHeight(playArea); } // Crop window to be size of grid Vector2 transform = Vector2.Transform(new Vector2(playArea.Right, playArea.Bottom), camera.GetViewMatrix()); graphics.PreferredBackBufferWidth = (int)Math.Round(transform.X); graphics.PreferredBackBufferHeight = (int)Math.Round(transform.Y); graphics.ApplyChanges(); // Move window next to console //Window.Position = new Point(ConsoleManager.ConsoleWindow.Right -8, 0); // Move window to the center //Window.Position = new Point((width /2) - (windowSize /2), (height / 2) - (windowSize / 2)); // Move window to the upper right corner Window.Position = new Point(screenSize.X - graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight - screenSize.Y); }