Ejemplo n.º 1
0
        public int movePlayer(Player player, List <Hex> hexPath, AnimationCallback callback)
        {
            int numHexesMoved = 0;

            if (hexPath.Count > 0)
            {
                // Get the center point of each hex
                List <HexPointF> centerPoints = new List <HexPointF>();
                foreach (Hex hex in hexPath)
                {
                    HexPointF centerPoint = hex.getCenter();
                    centerPoints.Add(centerPoint);
                }

                List <Vector3> vectorPath = new List <Vector3>();

                HexPointF[] centerArray = centerPoints.ToArray();
                int         maxPoints = centerArray.Length;
                HexPointF   point1, point2;
                for (int index = 0; index <= maxPoints - 2; index++)
                {
                    point1 = centerArray[index];
                    point2 = centerArray[index + 1];
                    vectorPath.AddRange(findPointsAlongLine3D(point1, point2, player.WalkingSpeed));
                }

                player.walk(vectorPath, callback);
            }

            return(hexPath.Count);
        }
Ejemplo n.º 2
0
        /// <summary>Calculates a (canonical X or Y) grid-coordinate for a point, from the supplied 'picking' matrix.</summary>
        /// <param name="matrix">The 'picking-matrix' matrix</param>
        /// <param name="point">The screen point identifying the hex to be 'picked'.</param>
        /// <returns>A (canonical X or Y) grid coordinate of the 'picked' hex.</returns>
        static int GetCoordinate(HexMatrix matrix, HexPointF point)
        {
            var points = new HexPointF[] { point };

            matrix.TransformPoints(points);
            return((int)Math.Floor((points[0].X + points[0].Y + 2F) / 3F));
        }
        /// <summary><c>HexCoords</c> for the hex at the screen point, with the given AutoScroll position.</summary>
        /// <param name="this"></param>
        /// <param name="point">Screen point specifying hex to be identified.</param>
        /// <param name="autoScroll">AutoScrollPosition for game-display Panel.</param>
        static HexCoords GetHexCoords(this IHexgrid @this, HexPointF point, HexSizeF autoScroll)
        {
            // Adjust for origin not as assumed by GetCoordinate().
            var grid = new HexSizeF(@this.GridSizeF().Width *2F / 3F, @this.GridSizeF().Height);

            point -= autoScroll + grid - new HexSizeF(@this.Margin.Width, @this.Margin.Height);

            return(HexCoords.NewCanonCoords(@this.GetCoordinate(@this.MatrixX(), point),
                                            @this.GetCoordinate(@this.MatrixY(), point)));
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public virtual HexCoords GetHexCoords(HexPointF point, HexSizeF autoScroll)
        {
            // Adjust for origin not as assumed by GetCoordinate().
            var grid = new HexSizeF(GridSizeF.Width * 2F / 3F, GridSizeF.Height);

            point -= autoScroll + grid - new HexSizeF(Margin.Width, Margin.Height);

            return(HexCoords.NewCanonCoords(GetCoordinate(_matrixX, point),
                                            GetCoordinate(_matrixY, point)));
        }
Ejemplo n.º 5
0
        /*
         * public Vector2 getCellCenter(Hex hex)
         * {
         *  HexPointF hexPointF = hex.getCenter();
         *
         *  if ( primitiveBatch != null )
         *      return new Vector2(hexPointF.X, hexPointF.Y);  // 2D coordinates map without a problem
         *
         *  // Else we have 3D coordinates and we have to map them to 2D
         *  Vector3 centerVector3 = new Vector3(hexPointF.X, 0.0f, hexPointF.Y);
         *  view = camera.ViewMatrix;
         *  grid.ViewMatrix = camera.ViewMatrix;
         *  Point centerPoint = convertWorldToScreenPoint(centerVector3);
         *  return new Vector2(centerPoint.X, centerPoint.Y);
         * }
         */

        public Vector2 getHexCenter(int i, int j)
        {
            Vector2 position = Vector2.Zero;

            Hex hex = getHex(i, j);

            if (hex != null)
            {
                HexPointF hexPointF = hex.getCenter();
                position = new Vector2(hexPointF.X, hexPointF.Y);
            }

            return(position);
        }
Ejemplo n.º 6
0
        public List <Vector3> findPointsAlongLine3D(GameEntity startEntity, GameEntity endEntity, float spacing)
        {
            Hex startHex = getHex(startEntity);

            if (startHex != null)
            {
                Hex endHex = getHex(endEntity);
                if (endHex != null)
                {
                    HexPointF startPointF = startHex.getCenter();
                    HexPointF endPointF   = endHex.getCenter();
                    return(findPointsAlongLine3D(startPointF, endPointF, spacing));
                }
            }

            return(null);
        }
Ejemplo n.º 7
0
        public List <Vector3> findPointsAlongLine3D(HexPointF start, HexPointF end, float spacing)
        {
            List <Vector3> points = new List <Vector3>();

            float xDifference         = end.X - start.X;
            float yDifference         = end.Y - start.Y;
            float absoluteXdifference = Math.Abs(start.X - end.X);
            float absoluteYdifference = Math.Abs(start.Y - end.Y);

            float lineLength = (float)Math.Sqrt((Math.Pow(absoluteXdifference, 2) + Math.Pow(absoluteYdifference, 2))); //pythagoras
            float steps      = lineLength / spacing;
            float xStep      = xDifference / steps;
            float yStep      = yDifference / steps;

            for (int i = 0; i < steps; i++)
            {
                float x = start.X + (xStep * i);
                float y = start.Y + (yStep * i);
                points.Add(new Vector3(x, 0, y));
            }

            return(points);
        }
 public static WpfPoint ToWpfPoint(this HexPointF @this)
 {
     return(new WpfPoint(@this.X, @this.Y));
 }
 /// <summary>Returns the location and extent in hexes, as a <see cref="CoordsRect"/>, of the current clipping region.</summary>
 /// <param name="this">The current {HexBoard}.</param>
 /// <param name="point"></param>
 /// <param name="size"></param>
 /// <returns>A Point structure containing pixel coordinates for the (centre of the) specified hex.</returns>
 public static CoordsRect GetClipInHexes(this IPanelModel @this, HexPointF point, HexSizeF size)
 => @this.GetClipInHexes(new RectangleF(point, size), @this.MapSizeHexes);
Ejemplo n.º 10
0
        public Vector3 getCellCenter(Hex hex)
        {
            HexPointF hexPointF = hex.getCenter();

            return(new Vector3(hexPointF.X, 0.0f, hexPointF.Y));
        }