예제 #1
0
        internal bool CheckCollision(Cursor currentPos, Cursor targetCursor, Moves dir)
        {
            bool      moveImpeded = true;
            FloorTile moveTile;
            FloorTile currentTile = FetchAt(currentPos);

            try
            {
                moveTile = FetchAt(targetCursor);
            } catch (IndexOutOfRangeException)
            {
                return(true);
            }
            if (currentPos.GetXPos - targetCursor.GetXPos != 0)
            {
                switch (currentPos.GetXPos - targetCursor.GetXPos)
                {
                // Moving LtR
                case -1:
                    if (currentTile.Right == false && moveTile.Left == false)
                    {
                        moveImpeded = false;
                    }
                    break;

                // Moving RtL
                case 1:
                    if (currentTile.Left == false && moveTile.Right == false)
                    {
                        moveImpeded = false;
                    }
                    break;
                }
            }
            else
            {
                switch (currentPos.GetYPos - targetCursor.GetYPos)
                {
                // Moving Up
                case 1:
                    if (currentTile.Top == false && moveTile.Bottom == false)
                    {
                        moveImpeded = false;
                    }
                    break;

                // Moving Down
                case -1:
                    if (currentTile.Bottom == false && moveTile.Top == false)
                    {
                        moveImpeded = false;
                    }
                    break;
                }
            }
            return(moveImpeded);
        }
예제 #2
0
        private bool DoMove(Cursor currentPos, Cursor targetCursor, Moves dir)
        {
            if (CheckCollision(currentPos, targetCursor, dir))
            {
                return(false);
            }
            else
            {
                FloorTile currentTile = FetchAt(currentPos);
                FloorTile moveTile    = FetchAt(targetCursor);

                Moveable toMove = currentTile.OnTile;

                moveTile.OnTile    = toMove;
                currentTile.OnTile = null;
                return(true);
            }
        }