private Vector2 DeterminePositionToDraw(Cell cell) { HexagonAxial axial = cell.ToAxial(); Vector2 centerPixel = axial.HexToPixel(); return(centerPixel); }
public override void Draw(GameTime gameTime) { Matrix transformMatrix = _cameraMap.SimView; ScreenManager.SpriteBatch.Begin(transformMatrix: transformMatrix); _gridRenderer.Draw(ScreenManager.SpriteBatch, _grid, _images, _cameraMap); Vector2 mousePosition = ScreenManager.InputManager.GetMousePosition(); Vector2 mousePositionWorld = _cameraMap.ConvertScreenToWorld(mousePosition); HexagonAxial axial = mousePositionWorld.PixelToHex(); _gridRenderer.DrawHexagonOutline(ScreenManager.SpriteBatch, axial.HexToPixel(), 2.0f, Color.DeepSkyBlue); _troll.Draw(ScreenManager.SpriteBatch); ScreenManager.SpriteBatch.End(); transformMatrix = _camera1.SimView; ScreenManager.SpriteBatch.Begin(transformMatrix: transformMatrix); ScreenManager.SpriteBatch.DrawCircle(_centerPixel, 5.0f, 10, Color.Red, 2); ScreenManager.SpriteBatch.FillRectangle(_topLeftPixel.X + 10.0f, _topLeftPixel.Y + 10.0f, 265.0f, 105.0f, new Color(Color.Salmon, 0.5f)); ScreenManager.SpriteBatch.FillRectangle(_topRightPixel.X - 340.0f, _topRightPixel.Y, 340.0f, 900.0f, Color.DarkSlateGray); Vector2 mousePosition1 = ScreenManager.InputManager.GetMousePosition(); Vector2 mousePosition2 = _camera1.ConvertScreenToWorld(mousePosition1); Vector2 mousePosition3 = mousePosition2 + _cameraMap.Position; Vector2 mousePosition4 = _camera1.ConvertWorldToScreen(mousePosition2); DrawString(string.Format("Camera Center: [{0} ; {1}]", _cameraMap.Position.X.ToString("0"), _cameraMap.Position.Y.ToString("0")), _topLeftPixel + new Vector2(15.0f, 35.0f), Color.DarkBlue); DrawString(string.Format("Mouse (Real): [{0} ; {1}]", mousePosition1.X.ToString("0"), mousePosition1.Y.ToString("0")), _topLeftPixel + new Vector2(15.0f, 55.0f), Color.DarkBlue); DrawString(string.Format("Mouse (ScreenToWorld): [{0} ; {1}]", mousePosition3.X.ToString("0"), mousePosition3.Y.ToString("0")), _topLeftPixel + new Vector2(15.0f, 75.0f), Color.DarkBlue); DrawString(string.Format("Mouse (WorldToScreen): [{0} ; {1}]", mousePosition4.X.ToString("0"), mousePosition4.Y.ToString("0")), _topLeftPixel + new Vector2(15.0f, 95.0f), Color.DarkBlue); ScreenManager.SpriteBatch.End(); }
private static void ParseCellLine(string line, HexagonGrid grid) { string[] pieces = line.Split(':'); HexagonAxial axial = GetHexagon(pieces[0]); List <CellData> cellData = GetCellData(pieces[1]); grid.SetCell(axial, cellData); }
private static HexagonAxial GetHexagon(string coordsString) { string[] coords = coordsString.Split(';'); float q = Convert.ToSingle(coords[0]); float r = Convert.ToSingle(coords[1]); var axial = new HexagonAxial(q, r); return(axial); }
public static HexagonAxial PixelToHex(this Vector2 pixel) { float q = pixel.X * Constants.TWO_THIRDS / Constants.HALF_HEX_WIDTH; //double r = (-pixel.X / 3.0f + (Math.Sqrt(3)/3.0f) * pixel.Y) / Constants.HALF_HEX_HEIGHT; double r = (-pixel.X / 3.0f + Constants.HALF * pixel.Y) / Constants.HALF_HEX_HEIGHT; var axial = new HexagonAxial(q, (float)r); axial = axial.Round(); return(axial); }
public void SetCell(HexagonAxial axial, List <CellData> data) { _cells[(short)axial.Q + _size, (short)axial.R + _size] = new Cell((short)axial.Q, (short)axial.R, data); }
public Troll(InputManager inputManager) { _inputManager = inputManager; _position = new HexagonAxial(0.0f, 0.0f); }