Ejemplo n.º 1
0
        /// <summary>
        /// Returns the center pixel of a hexagon
        /// </summary>
        public PointF HexToPixel()
        {
            HexAxial axial = ToAxial();
            PointF   pixel = axial.HexToPixel();

            return(pixel);
        }
Ejemplo n.º 2
0
        public void SetCell(Point mousePosition, int layerId, int paletteId, int terrainId)
        {
            HexAxial axial = DetermineHexAtMousePointer(mousePosition);

            _grid.SetCell(axial, layerId, paletteId, terrainId);
            IsDirty = true;
        }
Ejemplo n.º 3
0
        public void RemoveImageFromCell(Point mousePosition, int layerId)
        {
            HexAxial axial = DetermineHexAtMousePointer(mousePosition);

            _grid.RemoveImageFromCell(axial, layerId);
            IsDirty = true;
        }
Ejemplo n.º 4
0
        public HexAxial ToAxial()
        {
            float q     = X;
            float r     = Z;
            var   axial = new HexAxial(q, r);

            return(axial);
        }
Ejemplo n.º 5
0
        public HexAxial DetermineHexAtMousePointer(Point mousePosition)
        {
            var mousePositionRelativeToCenter = new PointF {
                X = mousePosition.X - Center.X, Y = mousePosition.Y - Center.Y
            };
            HexAxial axial = mousePositionRelativeToCenter.PixelToHex();

            return(axial);
        }
Ejemplo n.º 6
0
        private HexAxial GetHexagon(string coordsString)
        {
            string[] coords = coordsString.Split(';');
            float    q      = Convert.ToSingle(coords[0]);
            float    r      = Convert.ToSingle(coords[1]);

            var axial = new HexAxial(q, r);

            return(axial);
        }
Ejemplo n.º 7
0
        public static HexAxial PixelToHex(this PointF 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 HexAxial(q, (float)r);

            axial = axial.Round();

            return(axial);
        }
Ejemplo n.º 8
0
        private Cell GetCell(HexAxial axial)
        {
            HexCube cube = axial.ToCube();
            Cell    cell = GetCell(cube);

            if (cell == null)
            {
                cell = new Cell();
                _cells[(int)cube.Z + _size, (int)cube.Y + _size, (int)cube.X + _size] = cell;
            }

            return(cell);
        }
Ejemplo n.º 9
0
        public List <string> GetAllCells()
        {
            var cells = new List <string>();

            CellHandler handler = delegate(HexCube cube, Cell cell)
            {
                if (!cell.IsEmpty())
                {
                    HexAxial axial = cube.ToAxial();
                    cells.Add(string.Format(@"{0};{1}:{2}", axial.Q, axial.R, cell));
                }
            };

            IterateCells(handler);

            return(cells);
        }
Ejemplo n.º 10
0
        private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
        {
            statusStrip1.Items[0].Text = string.Format("Mouse Position: [X: {0} Y:{1}]", e.X, e.Y);
            PointF offset = DetermineOffset(e.X, e.Y);

            statusStrip1.Items[1].Text = string.Format("Offset From Center: [X: {0} Y:{1}]", offset.X, offset.Y);
            HexAxial axial = _map.DetermineHexAtMousePointer(new Point(e.X, e.Y));

            statusStrip1.Items[2].Text = string.Format("Selected Hex: [X: {0} Y:{1}]", axial.Q, axial.R);

            if (e.Button == MouseButtons.Left)
            {
                int deltaX = _panStartPoint.X - e.X;
                int deltaY = _panStartPoint.Y - e.Y;

                panel1.AutoScrollPosition = new Point(deltaX - panel1.AutoScrollPosition.X, deltaY - panel1.AutoScrollPosition.Y);
            }
        }
Ejemplo n.º 11
0
        public void RemoveImageFromCell(HexAxial axial, int layerId)
        {
            Cell cell = GetCell(axial);

            cell.RemoveTerrain(layerId);
        }
Ejemplo n.º 12
0
        public void SetCell(HexAxial axial, int layerId, int paletteId, int terrainId)
        {
            Cell cell = GetCell(axial);

            cell.AddCellData(layerId, paletteId, terrainId);
        }