How to Draw a Hex In Monogame Code

public void DrawLineSegment(Vector2 point1, Vector2 point2, Color color, int lineWidth)
        {
            float angle = (float)Math.Atan2(point2.Y - point1.Y, point2.X - point1.X);
            float length = Vector2.Distance(point1, point2);

            spriteBatch.End();
            spriteBatch.Begin();

            spriteBatch.Draw(_line, point1, null, color,
            angle, Vector2.Zero, new Vector2(length, lineWidth),
            SpriteEffects.None, 0f);
        }

        public void DrawHex(Vector2 hexLocation, bool selectedColor)
        {
            Color borderColor;

            if (selectedColor)
            {
                _line.SetData(new[] { _selectedLineColor });
                borderColor = _selectedLineColor;
            }

            else
            {
                _line.SetData(new[] { _lineColor });
                borderColor = _lineColor;
            }


            DrawLineSegment(new Vector2(hexLocation.X + _hexWidth - _hexSide, hexLocation.Y), new Vector2(hexLocation.X + _hexSide, hexLocation.Y), borderColor, _lineWidth);

            DrawLineSegment(new Vector2(hexLocation.X + _hexSide, hexLocation.Y), new Vector2(hexLocation.X + _hexWidth, hexLocation.Y + (_hexHeight / 2)), borderColor, _lineWidth );

            DrawLineSegment(new Vector2(hexLocation.X + _hexWidth, hexLocation.Y + (_hexHeight / 2)), new Vector2(hexLocation.X + _hexSide, hexLocation.Y + _hexHeight), borderColor, _lineWidth );

            DrawLineSegment(new Vector2(hexLocation.X + _hexSide, hexLocation.Y + _hexHeight), new Vector2(hexLocation.X + _hexWidth - _hexSide, hexLocation.Y + _hexHeight), borderColor, _lineWidth);

            DrawLineSegment(new Vector2(hexLocation.X + _hexWidth - _hexSide, hexLocation.Y + _hexHeight), new Vector2(hexLocation.X, hexLocation.Y + (_hexHeight / 2)), borderColor, _lineWidth);

            DrawLineSegment(new Vector2(hexLocation.X, hexLocation.Y + (_hexHeight / 2)), new Vector2(hexLocation.X + _hexWidth - _hexSide, hexLocation.Y), borderColor, _lineWidth);
        }


Lost Password