예제 #1
0
        public void SetRelativeTo(FieldCell cell, int stepX, int stepY)
        {
            float posX = stepX != 0 ? (cell.CellCenterPx() + stepX * Constant.CELL_WIDTH) : px;
            float posY = stepY != 0 ? (cell.CellCenterPy() + stepY * Constant.CELL_HEIGHT) : py;

            SetPos(posX, posY);
        }
예제 #2
0
        public void MoveOutOfCell(FieldCell c)
        {
            Debug.Assert(IsMoving());

            switch (direction)
            {
            case Direction.LEFT:
                Debug.Assert(c.px < px);
                if (px - c.CellCenterPx() < Constant.CELL_WIDTH)
                {
                    SetRelativeTo(c, 1, 0);
                }
                break;

            case Direction.RIGHT:
                Debug.Assert(c.px > px);
                if (c.CellCenterPx() - px < Constant.CELL_WIDTH)
                {
                    SetRelativeTo(c, -1, 0);
                }
                break;

            case Direction.UP:
                Debug.Assert(c.py < py);
                if (py - c.CellCenterPy() < Constant.CELL_HEIGHT)
                {
                    SetRelativeTo(c, 0, 1);
                }
                break;

            case Direction.DOWN:
                Debug.Assert(c.py > py);
                if (c.CellCenterPy() - py < Constant.CELL_HEIGHT)
                {
                    SetRelativeTo(c, 0, -1);
                }
                break;
            }
        }