Ejemplo n.º 1
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.º 2
0
        private void DrawFlame(Context context, FieldCell cell)
        {
            int x = cell.GetCx() * cellWidth;
            int y = cell.GetCy() * cellHeight;

            context.FillRect(x, y, cellWidth, cellHeight, Color.Red);
        }
Ejemplo n.º 3
0
        private void DrawCells(Context context)
        {
            FieldCellSlot[] slots = field.GetSlots();

            bool drawSlotSize = CVars.g_drawSlotSize.boolValue;

            foreach (FieldCellSlot slot in slots)
            {
                FieldCell cell = slot.staticCell;
                if (cell != null)
                {
                    DrawCell(context, cell);
                }

                if (slot.MovableCount() > 0)
                {
                    foreach (MovableCell movableCell in slot.movableCells)
                    {
                        DrawCell(context, movableCell);
                    }
                }

                if (slot.Size() > 0 && drawSlotSize)
                {
                    float drawX = Util.Cx2Px(slot.cx) - 0.5f * cellWidth;
                    float drawY = Util.Cy2Py(slot.cy) - 0.5f * cellHeight;
                    context.DrawString(drawX, drawY, "" + slot.Size());
                }
            }
        }
Ejemplo n.º 4
0
        private void DrawCellImage(Context context, FieldCell cell, TextureImage image)
        {
            float drawX = cell.GetPx() - 0.5f * image.GetWidth();
            float drawY = cell.GetPy() - 0.5f * image.GetHeight();

            context.DrawImage(image, drawX, drawY);
        }
Ejemplo n.º 5
0
 private void DrawCell(Context context, FieldCell cell)
 {
     if (cell.IsBrick())
     {
         DrawBrick(context, cell.AsBrick());
     }
     else if (cell.IsSolid())
     {
         DrawSolid(context, cell);
     }
     else if (cell.IsBomb())
     {
         DrawBomb(context, cell.AsBomb());
     }
     else if (cell.IsFlame())
     {
         DrawFlame(context, cell.AsFlame());
     }
     else if (cell.IsPowerup())
     {
         DrawPowerup(context, cell.AsPowerup());
     }
     else if (cell.IsPlayer())
     {
         DrawPlayer(context, cell.AsPlayer());
     }
 }
        public void Add(int x, int y, FieldCell cell)
        {
            Remove(cell);

            int slotIndex = GetSlotIndex(x, y);
            slots[slotIndex].AddCell(cell);
            cell.slotIndex = slotIndex;
        }
Ejemplo n.º 7
0
 public void AddCell(FieldCell cell)
 {
     cells.Add(cell.GetCx(), cell.GetCy(), cell);
     if (cell.IsMovable())
     {
         AddMovable(cell.AsMovable());
     }
 }
Ejemplo n.º 8
0
 public void RemoveCell(FieldCell cell)
 {
     cells.Remove(cell);
     if (cell.IsMovable())
     {
         RemoveMovable(cell.AsMovable());
     }
     CancelAllTimers(cell);
 }
Ejemplo n.º 9
0
        /* Returns true if can be spread more */
        private bool SetFlame(Bomb bomb, int cx, int cy)
        {
            if (!IsInsideField(cx, cy))
            {
                return(false);
            }

            FieldCellSlot slot = GetSlot(cx, cy);

            FieldCell staticCell = slot.staticCell;

            if (staticCell != null)
            {
                if (staticCell.IsSolid())
                {
                    return(false);
                }

                if (staticCell.IsBrick())
                {
                    BrickCell brick = staticCell.AsBrick();
                    if (!brick.destroyed)
                    {
                        brick.Destroy();
                    }

                    return(false);
                }

                if (staticCell.IsPowerup())
                {
                    staticCell.AsPowerup().RemoveFromField();
                    return(false);
                }
            }

            if (slot.MovableCount() > 0)
            {
                LinkedList <FieldCell> tempList = new LinkedList <FieldCell>();
                slot.GetCells(tempList);

                foreach (FieldCell cell in tempList)
                {
                    if (cell.IsBomb())
                    {
                        cell.AsBomb().Blow();
                    }
                    else if (cell.IsPlayer())
                    {
                        KillPlayer(cell.AsPlayer());
                    }
                }
            }

            SetFlame(bomb.player, cx, cy);
            return(true);
        }
Ejemplo n.º 10
0
        public void Add(int x, int y, FieldCell cell)
        {
            Remove(cell);

            int slotIndex = GetSlotIndex(x, y);

            slots[slotIndex].AddCell(cell);
            cell.slotIndex = slotIndex;
        }
 public void AddCell(FieldCell cell)
 {
     if (cell.IsMovable())
     {
         movableCells.Add(cell.AsMovable());
     }
     else
     {
         Debug.Assert(staticCell == null);
         staticCell = cell;
     }
 }
Ejemplo n.º 12
0
 public void RemoveCell(FieldCell cell)
 {
     if (cell.IsMovable())
     {
         movableCells.Remove(cell.AsMovable());
     }
     else
     {
         Debug.Assert(staticCell == cell);
         staticCell = null;
     }
 }
        public bool Remove(FieldCell cell)
        {
            int slotIndex = cell.slotIndex;
            if (slotIndex != -1)
            {
                slots[slotIndex].RemoveCell(cell);
                cell.slotIndex = -1;

                return true;
            }

            return false;
        }
Ejemplo n.º 14
0
        public bool Contains(FieldCell cell)
        {
            if (staticCell == cell)
            {
                return(true);
            }

            if (cell.IsMovable() && movableCells.Contains(cell.AsMovable()))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 15
0
        public bool Remove(FieldCell cell)
        {
            int slotIndex = cell.slotIndex;

            if (slotIndex != -1)
            {
                slots[slotIndex].RemoveCell(cell);
                cell.slotIndex = -1;

                return(true);
            }

            return(false);
        }
        public bool Contains(FieldCell cell)
        {
            if (staticCell == cell)
            {
                return true;
            }

            if (cell.IsMovable() && movableCells.Contains(cell.AsMovable()))
            {
                return true;
            }

            return false;
        }
 public void Reset()
 {
     staticCell = null;
     movableCells.Clear();
 }
 public static float OverlapX(FieldCell a, FieldCell b)
 {
     float overlapX = Constant.CELL_WIDTH - Math.Abs(a.px - b.px);
     return overlapX > 0 ? overlapX : 0;
 }
 /* Checks if objects collide */
 public virtual bool Collides(FieldCell other)
 {
     return CheckBounds2BoundsCollision(other)
         || CheckBounds2CellCollision(other)
         || CheckCell2BoundsCollision(other);
 }
 /* Checks cell-to-bounds collision: objects collide if caller's bounding box collides with callee's
  * cell */
 public bool CheckCell2BoundsCollision(FieldCell other)
 {
     return other.CheckBounds2CellCollision(this);
 }
 /* Checks bounds-to-bounds collision: objects collide if bounding boxes collide */
 public bool CheckBounds2BoundsCollision(FieldCell other)
 {
     return Math.Abs(px - other.px) < Constant.CELL_WIDTH && Math.Abs(py - other.py) < Constant.CELL_HEIGHT;
 }
 public bool Contains(FieldCell cell)
 {
     int slotIndex = GetSlotIndex(cell.cx, cell.cy);
     return slots[slotIndex].Contains(cell);
 }
Ejemplo n.º 23
0
 public FieldCellSlot GetSlot(FieldCell cell)
 {
     return(GetSlot(cell.cx, cell.cy));
 }
Ejemplo n.º 24
0
 private void ShuffleCells(FieldCell[] array, int size)
 {
     ArrayUtils.Shuffle(array, size);
 }
Ejemplo n.º 25
0
 private bool CheckCollision(MovableCell c1, FieldCell c2)
 {
     return c1.Collides(c2) && c1.HandleCollision(c2);
 }
Ejemplo n.º 26
0
 private bool CheckCell(FieldCell cell)
 {
     return cells.Contains(cell);
 }
Ejemplo n.º 27
0
 public void RemoveCell(FieldCell cell)
 {
     cells.Remove(cell);
     if (cell.IsMovable())
     {
         RemoveMovable(cell.AsMovable());
     }
     CancelAllTimers(cell);
 }
Ejemplo n.º 28
0
 public FieldCellSlot GetSlot(FieldCell cell)
 {
     return GetSlot(cell.cx, cell.cy);
 }
        public virtual bool HandleCollision(FieldCell cell)
        {
            if (cell.IsMovable())
            {
                return HandleCollision(cell.AsMovable());
            }

            return HandleStaticCollision(cell);
        }
Ejemplo n.º 30
0
        protected override bool HandleStaticCollision(FieldCell other)
        {
            if (other.IsFlame())
            {
                return HandleCollision(other.AsFlame());
            }

            if (other.IsPowerup())
            {
                return HandleCollision(other.AsPowerup());
            }

            return HandleObstacleCollistion(other);
        }
Ejemplo n.º 31
0
        public bool Contains(FieldCell cell)
        {
            int slotIndex = GetSlotIndex(cell.cx, cell.cy);

            return(slots[slotIndex].Contains(cell));
        }
Ejemplo n.º 32
0
 public void AddCell(FieldCell cell)
 {
     cells.Add(cell.GetCx(), cell.GetCy(), cell);
     if (cell.IsMovable())
     {
         AddMovable(cell.AsMovable());
     }
 }
Ejemplo n.º 33
0
        //////////////////////////////////////////////////////////////////////////////

        #region Collider

        /* Checks if objects collide */
        public virtual bool Collides(FieldCell other)
        {
            return(CheckBounds2BoundsCollision(other) ||
                   CheckBounds2CellCollision(other) ||
                   CheckCell2BoundsCollision(other));
        }
        public void MoveFromOverlap(FieldCell other)
        {
            Debug.Assert(IsMoving());

            float dx = OverlapX(other);
            float dy = OverlapY(other);

            MoveBackX(dx);
            MoveBackY(dy);
        }
        /* Not movable cell */
        protected virtual bool HandleStaticCollision(FieldCell other)
        {
            if (other.IsObstacle())
            {
                MoveFromOverlap(other);
                return true;
            }

            return false;
        }
 /* 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);
        }
 /* Checks cell-to-cell collision: objects collide only if cells collide */
 public bool CheckCell2CellCollision(FieldCell other)
 {
     return cx == other.cx && cy == other.cy;
 }
 public new bool CheckBounds2BoundsCollision(FieldCell other)
 {
     return base.CheckBounds2BoundsCollision(other);
 }
 public float OverlapY(FieldCell other)
 {
     return OverlapY(this, other);
 }
Ejemplo n.º 41
0
 public void Reset()
 {
     staticCell = null;
     movableCells.Clear();
 }
 public static float OverlapY(FieldCell a, FieldCell b)
 {
     float overlapY = Constant.CELL_HEIGHT - Math.Abs(a.py - b.py);
     return overlapY > 0 ? overlapY : 0;
 }
Ejemplo n.º 43
0
 public float OverlapY(FieldCell other)
 {
     return(OverlapY(this, other));
 }
Ejemplo n.º 44
0
 private void DrawCellRect(Context context, FieldCell cell, Color color)
 {
     DrawCellRect(context, cell.GetCx(), cell.GetCy(), color);
 }
Ejemplo n.º 45
0
        public static float OverlapX(FieldCell a, FieldCell b)
        {
            float overlapX = Constant.CELL_WIDTH - Math.Abs(a.px - b.px);

            return(overlapX > 0 ? overlapX : 0);
        }
Ejemplo n.º 46
0
        internal bool HandleObstacleCollistion(FieldCell other)
        {
            Debug.Assert(isActive);
            Debug.Assert(IsMoving());

            MoveOutOfCell(other);

            if (TryJellyOnObstacle())
            {
                return true;
            }

            StopMoving();

            return true;
        }
Ejemplo n.º 47
0
        public static float OverlapY(FieldCell a, FieldCell b)
        {
            float overlapY = Constant.CELL_HEIGHT - Math.Abs(a.py - b.py);

            return(overlapY > 0 ? overlapY : 0);
        }
Ejemplo n.º 48
0
 private void DrawSolid(Context context, FieldCell cell)
 {
     DrawCellImage(context, cell, solidImage);
 }
        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;
            }
        }
Ejemplo n.º 50
0
 /* Checks cell-to-cell collision: objects collide only if cells collide */
 public bool CheckCell2CellCollision(FieldCell other)
 {
     return(cx == other.cx && cy == other.cy);
 }
Ejemplo n.º 51
0
        public override bool HandleCollision(FieldCell cell)
        {
            if (IsAlive)
            {
                return base.HandleCollision(cell);
            }

            return false;
        }
Ejemplo n.º 52
0
 private bool CheckCell(FieldCell cell)
 {
     return(cells.Contains(cell));
 }
Ejemplo n.º 53
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);
 }
Ejemplo n.º 54
0
 private bool CheckCollision(MovableCell c1, FieldCell c2)
 {
     return(c1.Collides(c2) && c1.HandleCollision(c2));
 }
Ejemplo n.º 55
0
 /* Checks cell-to-bounds collision: objects collide if caller's bounding box collides with callee's
  * cell */
 public bool CheckCell2BoundsCollision(FieldCell other)
 {
     return(other.CheckBounds2CellCollision(this));
 }
 public new bool CheckCell2CellCollision(FieldCell other)
 {
     return base.CheckCell2CellCollision(other);
 }
Ejemplo n.º 57
0
 /* Checks bounds-to-bounds collision: objects collide if bounding boxes collide */
 public bool CheckBounds2BoundsCollision(FieldCell other)
 {
     return(Math.Abs(px - other.px) < Constant.CELL_WIDTH && Math.Abs(py - other.py) < Constant.CELL_HEIGHT);
 }