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 DrawFlame(Context context, FieldCell cell) { int x = cell.GetCx() * cellWidth; int y = cell.GetCy() * cellHeight; context.FillRect(x, y, cellWidth, cellHeight, Color.Red); }
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()); } } }
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); }
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; }
public void AddCell(FieldCell cell) { cells.Add(cell.GetCx(), cell.GetCy(), cell); if (cell.IsMovable()) { AddMovable(cell.AsMovable()); } }
public void RemoveCell(FieldCell cell) { cells.Remove(cell); if (cell.IsMovable()) { RemoveMovable(cell.AsMovable()); } CancelAllTimers(cell); }
/* 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); }
public void AddCell(FieldCell cell) { if (cell.IsMovable()) { movableCells.Add(cell.AsMovable()); } else { Debug.Assert(staticCell == null); staticCell = cell; } }
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; }
public bool Contains(FieldCell cell) { if (staticCell == cell) { return(true); } if (cell.IsMovable() && movableCells.Contains(cell.AsMovable())) { return(true); } return(false); }
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); }
public FieldCellSlot GetSlot(FieldCell cell) { return(GetSlot(cell.cx, cell.cy)); }
private void ShuffleCells(FieldCell[] array, int size) { ArrayUtils.Shuffle(array, size); }
private bool CheckCollision(MovableCell c1, FieldCell c2) { return c1.Collides(c2) && c1.HandleCollision(c2); }
private bool CheckCell(FieldCell cell) { return cells.Contains(cell); }
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); }
protected override bool HandleStaticCollision(FieldCell other) { if (other.IsFlame()) { return HandleCollision(other.AsFlame()); } if (other.IsPowerup()) { return HandleCollision(other.AsPowerup()); } return HandleObstacleCollistion(other); }
public bool Contains(FieldCell cell) { int slotIndex = GetSlotIndex(cell.cx, cell.cy); return(slots[slotIndex].Contains(cell)); }
////////////////////////////////////////////////////////////////////////////// #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); }
public static float OverlapY(FieldCell a, FieldCell b) { float overlapY = Constant.CELL_HEIGHT - Math.Abs(a.py - b.py); return overlapY > 0 ? overlapY : 0; }
public float OverlapY(FieldCell other) { return(OverlapY(this, other)); }
private void DrawCellRect(Context context, FieldCell cell, Color color) { DrawCellRect(context, cell.GetCx(), cell.GetCy(), color); }
public static float OverlapX(FieldCell a, FieldCell b) { float overlapX = Constant.CELL_WIDTH - Math.Abs(a.px - b.px); return(overlapX > 0 ? overlapX : 0); }
internal bool HandleObstacleCollistion(FieldCell other) { Debug.Assert(isActive); Debug.Assert(IsMoving()); MoveOutOfCell(other); if (TryJellyOnObstacle()) { return true; } StopMoving(); return true; }
public static float OverlapY(FieldCell a, FieldCell b) { float overlapY = Constant.CELL_HEIGHT - Math.Abs(a.py - b.py); return(overlapY > 0 ? overlapY : 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; } }
/* Checks cell-to-cell collision: objects collide only if cells collide */ public bool CheckCell2CellCollision(FieldCell other) { return(cx == other.cx && cy == other.cy); }
public override bool HandleCollision(FieldCell cell) { if (IsAlive) { return base.HandleCollision(cell); } return false; }
private bool CheckCell(FieldCell cell) { return(cells.Contains(cell)); }
/* 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); }
private bool CheckCollision(MovableCell c1, FieldCell c2) { return(c1.Collides(c2) && c1.HandleCollision(c2)); }
/* 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); }
/* 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); }