/* Checks bounds-to-cell collision: objects collide if caller's cell collides with callee's
  * bounding box */
 public bool CheckBounds2CellCollision(FieldCell other)
 {
     return Math.Abs(px - other.CellCenterPx()) < Constant.CELL_WIDTH && Math.Abs(py - other.CellCenterPy()) < Constant.CELL_HEIGHT;
 }
        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);
        }
Exemplo n.º 3
0
 /* Checks bounds-to-cell collision: objects collide if caller's cell collides with callee's
  * bounding box */
 public bool CheckBounds2CellCollision(FieldCell other)
 {
     return(Math.Abs(px - other.CellCenterPx()) < Constant.CELL_WIDTH && Math.Abs(py - other.CellCenterPy()) < Constant.CELL_HEIGHT);
 }
        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;
            }
        }