/* 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); }
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); }
private void RemoveMovable(MovableCell cell) { if (cell.addedToList) { movableCells.Remove(cell); cell.addedToList = false; } }
public bool CheckStaticCollisions(MovableCell movable) { bool hasCollision = false; hasCollision |= CheckWallCollisions(movable); hasCollision |= CheckStillCellsCollisions(movable); return(hasCollision); }
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); }
public bool ContainsPlayer() { for (int i = 0; i < movableCells.Count; ++i) { MovableCell cell = movableCells[i]; if (cell.IsPlayer()) { return(true); } } return(false); }
public Bomb GetBomb() { for (int i = 0; i < movableCells.Count; ++i) { MovableCell cell = movableCells[i]; if (cell.IsBomb()) { return(cell.AsBomb()); } } return(null); }
protected override bool HandleCollision(MovableCell other) { if (other.IsBomb()) { return(HandleCollision(other.AsBomb())); } if (other.IsPlayer()) { return(HandleCollision(other.AsPlayer())); } return(false); }
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); } }
public bool ContainsObstacle() { if (staticCell != null) { return(staticCell.IsObstacle()); } for (int i = 0; i < movableCells.Count; ++i) { MovableCell cell = movableCells[i]; if (cell.IsObstacle()) { return(true); } } return(false); }
////////////////////////////////////////////////////////////////////////////// #region Collisions private void HandleCollisions() { // copy to the temp list Debug.Assert(m_tempMovableList.Count == 0); foreach (MovableCell movable in movableCells) { m_tempMovableList.Add(movable); } // static collisions for (int i = 0; i < m_tempMovableList.Count; ++i) { CheckStaticCollisions(m_tempMovableList[i]); } m_tempMovableList.Clear(); // copy to the temp list foreach (MovableCell movable in movableCells) { m_tempMovableList.Add(movable); } // movable-to-movable collisions for (int i = 0; i < m_tempMovableList.Count - 1; ++i) { MovableCell c1 = m_tempMovableList[i]; for (int j = i + 1; j < m_tempMovableList.Count; ++j) { MovableCell c2 = m_tempMovableList[j]; CheckCollision(c1, c2); } } // clear m_tempMovableList.Clear(); }
private bool CheckCollision(MovableCell c1, FieldCell c2) { return(c1.Collides(c2) && c1.HandleCollision(c2)); }
////////////////////////////////////////////////////////////////////////////// #region Cells public void MovableCellChanged(MovableCell movable, int oldCx, int oldCy) { AddCell(movable); }