Ejemplo n.º 1
0
        //////////////////////////////////////////////////////////////////////////////

        #region Collider

        protected override bool HandleCollision(MovableCell other)
        {
            Debug.Assert(isActive);

            if (other.IsPlayer())
            {
                return(other.AsPlayer().HandleCollision(this));
            }

            if (other.IsBomb())
            {
                return(HandleCollision(other.AsBomb()));
            }

            if (other.IsObstacle())
            {
                return(HandleObstacleCollistion(other));
            }

            return(false);
        }
Ejemplo n.º 2
0
        protected override bool HandleCollision(MovableCell other)
        {
            Debug.Assert(isActive);

            if (other.IsPlayer())
            {
                return other.AsPlayer().HandleCollision(this);
            }

            if (other.IsBomb())
            {
                return HandleCollision(other.AsBomb());
            }

            if (other.IsObstacle())
            {
                return HandleObstacleCollistion(other);
            }

            return false;
        }
Ejemplo n.º 3
0
 private void RemoveMovable(MovableCell cell)
 {
     if (cell.addedToList)
     {
         movableCells.Remove(cell);
         cell.addedToList = false;
     }
 }
Ejemplo n.º 4
0
        private bool CheckWallCollisions(MovableCell movable)
        {
            float dx = movable.moveDx;
            float dy = movable.moveDy;

            if (dx > 0)
            {
                float maxX = GetMaxPx();
                if (movable.GetPx() > maxX)
                {
                    movable.SetPosX(maxX);
                    movable.HandleWallCollision();

                    return true;
                }
            }
            else if (dx < 0)
            {
                float minX = GetMinPx();
                if (movable.GetPx() < minX)
                {
                    movable.SetPosX(minX);
                    movable.HandleWallCollision();

                    return true;
                }
            }

            if (dy > 0)
            {
                float maxY = GetMaxPy();
                if (movable.GetPy() > maxY)
                {
                    movable.SetPosY(maxY);
                    movable.HandleWallCollision();

                    return true;
                }
            }
            else if (dy < 0)
            {
                float minY = GetMinPy();
                if (movable.GetPy() < minY)
                {
                    movable.SetPosY(minY);
                    movable.HandleWallCollision();

                    return true;
                }
            }

            return false;
        }
Ejemplo n.º 5
0
        private bool CheckStillCollisions(MovableCell movable, FieldCellSlot slot)
        {
            if (slot != null)
            {
                FieldCell staticCell = slot.staticCell;
                if (staticCell != null)
                {
                    return CheckCollision(movable, staticCell);
                }

                bool handled = false;

                List<MovableCell> movableCells = slot.movableCells;
                for (int i = 0; i < movableCells.Count; ++i)
                {
                    MovableCell other = movableCells[i];
                    if (!other.IsMoving() && movable != other)
                    {
                        handled |= CheckCollision(movable, other);
                    }
                }

                return handled;
            }

            return false;
        }
Ejemplo n.º 6
0
        /* Checks collision with static cells (bricks and solids) + still movable obstacles (not moving bombs) */
        private bool CheckStillCellsCollisions(MovableCell movable)
        {
            int cx = movable.cx;
            int cy = movable.cy;

            int stepX = Math.Sign(movable.px - movable.CellCenterPx());
            int stepY = Math.Sign(movable.py - movable.CellCenterPy());

            bool hasStepX = stepX != 0;
            bool hasStepY = stepY != 0;

            bool hasCollision = false;

            hasCollision |= CheckStillCollisions(movable, GetSlot(cx, cy));

            if (hasStepX && hasStepY)
            {
                hasCollision |= CheckStillCollisions(movable, GetSlot(cx + stepX, cy));
                hasCollision |= CheckStillCollisions(movable, GetSlot(cx, cy + stepY));
                hasCollision |= CheckStillCollisions(movable, GetSlot(cx + stepX, cy + stepY));
            }
            else if (hasStepX)
            {
                hasCollision |= CheckStillCollisions(movable, GetSlot(cx + stepX, cy));
            }
            else if (hasStepY)
            {
                hasCollision |= CheckStillCollisions(movable, GetSlot(cx, cy + stepY));
            }

            return hasCollision;
        }
Ejemplo n.º 7
0
 private bool CheckCollision(MovableCell c1, FieldCell c2)
 {
     return c1.Collides(c2) && c1.HandleCollision(c2);
 }
Ejemplo n.º 8
0
        private void AddMovable(MovableCell cell)
        {
            if (!cell.addedToList)
            {
                cell.addedToList = true;

                // added into the list sorted bombs first, players next
                for (LinkedListNode<MovableCell> node = movableCells.First; node != null; node = node.Next)
                {
                    if (cell.type <= node.Value.type)
                    {
                        movableCells.AddBefore(node, cell);
                        return;
                    }
                }
                movableCells.AddLast(cell);
            }
        }
Ejemplo n.º 9
0
 public void MovableCellChanged(MovableCell movable, int oldCx, int oldCy)
 {
     AddCell(movable);
 }
Ejemplo n.º 10
0
        public bool CheckStaticCollisions(MovableCell movable)
        {
            bool hasCollision = false;

            hasCollision |= CheckWallCollisions(movable);
            hasCollision |= CheckStillCellsCollisions(movable);

            return hasCollision;
        }
Ejemplo n.º 11
0
 /* Movable cell */
 protected virtual bool HandleCollision(MovableCell other)
 {
     return(false);
 }
Ejemplo n.º 12
0
        protected override bool HandleCollision(MovableCell other)
        {
            if (other.IsBomb())
            {
                return HandleCollision(other.AsBomb());
            }

            if (other.IsPlayer())
            {
                return HandleCollision(other.AsPlayer());
            }

            return false;
        }
 /* Movable cell */
 protected virtual bool HandleCollision(MovableCell other)
 {
     return false;
 }