コード例 #1
0
        public TileCell GetCellCoordinateInDirection(Int32 sourceX, Int32 sourceY, CardinalDirection dir)
        {
            Int32    targetX, targetY;
            TileCell cell = GetCellCoordinateInDirection(sourceX, sourceY, dir, out targetX, out targetY);

            return(cell);
        }
コード例 #2
0
        public CardinalDirection GetAdjacentDirectionFromSourceToTargetCell(TileCell source, TileCell target)
        {
            CardinalDirection dir = CardinalDirection.None;

            if (source != null && target != null)
            {
                if (source.X == target.X)
                {
                    if (target.Y > source.Y)
                    {
                        dir = CardinalDirection.South;
                    }
                    else if (target.Y < source.Y)
                    {
                        dir = CardinalDirection.North;
                    }
                }
                else if (source.Y == target.Y)
                {
                    if (target.X > source.X)
                    {
                        dir = CardinalDirection.East;
                    }
                    else if (target.X < source.X)
                    {
                        dir = CardinalDirection.West;
                    }
                }
            }

            return(dir);
        }
コード例 #3
0
        public TileCell GetCellAtRealCoordinate(Double x, Double y)
        {
            Int32    mapColumn = (Int32)(x / TileSize);
            Int32    mapRow    = (Int32)(y / TileSize);
            TileCell cell      = GetCellAtCoordinate(mapColumn, mapRow);

            return(cell);
        }
コード例 #4
0
        /// <summary>
        /// Returns whether we consider the supplied TileCell to equal this one.  They must have the
        /// same position.
        /// </summary>
        public override Boolean Equals(Object other)
        {
            Boolean  equals    = false;
            TileCell otherCell = other as TileCell;

            if (otherCell != null)
            {
                if (X == otherCell.X && Y == otherCell.Y && String.Equals(ParentKey, otherCell.ParentKey))
                {
                    equals = true;
                }
            }
            return(equals);
        }
コード例 #5
0
        public List <IAStarNode> NeighborNodes(IAStarNode current)
        {
            List <IAStarNode> neighbors = new List <IAStarNode>();

            TileCell northCell = GetCellCoordinateInDirection(current.X, current.Y, CardinalDirection.North);
            TileCell eastCell  = GetCellCoordinateInDirection(current.X, current.Y, CardinalDirection.East);
            TileCell southCell = GetCellCoordinateInDirection(current.X, current.Y, CardinalDirection.South);
            TileCell westCell  = GetCellCoordinateInDirection(current.X, current.Y, CardinalDirection.West);

            if (northCell != null && northCell.IsVoid)
            {
                northCell = null;
            }
            if (eastCell != null && eastCell.IsVoid)
            {
                eastCell = null;
            }
            if (southCell != null && southCell.IsVoid)
            {
                southCell = null;
            }
            if (westCell != null && westCell.IsVoid)
            {
                westCell = null;
            }

            if (northCell != null)
            {
                neighbors.Add(northCell);
            }
            if (eastCell != null)
            {
                neighbors.Add(eastCell);
            }
            if (southCell != null)
            {
                neighbors.Add(southCell);
            }
            if (westCell != null)
            {
                neighbors.Add(westCell);
            }

            return(neighbors);
        }
コード例 #6
0
        /// <summary>
        /// From some source position, given a direction, returns the cell coordinates in that direction.
        /// The returned coordinates may not be on the map, so null will be returned.
        /// </summary>
        public TileCell GetCellCoordinateInDirection(Int32 sourceX, Int32 sourceY, CardinalDirection dir, out Int32 targetX, out Int32 targetY)
        {
            targetX = sourceX;
            targetY = sourceY;

            switch (dir)
            {
            case CardinalDirection.North: targetY--; break;

            case CardinalDirection.East: targetX++; break;

            case CardinalDirection.South: targetY++; break;

            case CardinalDirection.West: targetX--; break;
            }

            TileCell targetCell = GetCellAtCoordinate(targetX, targetY);

            return(targetCell);
        }
コード例 #7
0
        public TileCell GetCellAtPosition(Position p)
        {
            TileCell cell = GetCellAtRealCoordinate(p.BottomCenterX, p.BottomCenterY);

            return(cell);
        }