public void DropPowerups(Player player) { FieldCellSlot[] slots = new FieldCellSlot[GetWidth() * GetHeight()]; int slotsCount = GetEmptySlots(slots); if (slotsCount == 0) { return; } ShuffleSlots(slots, slotsCount); PowerupList powerups = player.powerups; int slotIndex = 0; for (int powerupIndex = 0; powerupIndex < Powerups.Count && slotIndex < slots.Length; ++powerupIndex) { int count = powerups.GetCount(powerupIndex); for (int i = 0; i < count && slotIndex < slots.Length; ++i) { FieldCellSlot slot = slots[slotIndex++]; PowerupCell cell = new PowerupCell(powerupIndex, slot.cx, slot.cy); AddCell(cell); } } }
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); }
/* 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); }
private void SetFlame(Player player, int cx, int cy) { FieldCellSlot slot = GetSlot(cx, cy); FlameCell flame = slot.GetFlame(); if (flame != null && flame.player == player) { flame.RemoveFromField(); } AddCell(new FlameCell(player, cx, cy)); }
public void UpdateSlot(float delta, FieldCellSlot slot) { slot.GetCells(m_tempCellsList); if (m_tempCellsList.Count > 0) { foreach (FieldCell cell in m_tempCellsList) { cell.Update(delta); } m_tempCellsList.Clear(); } }
private int GetEmptySlots(FieldCellSlot[] array) { int count = 0; FieldCellSlot[] slots = cells.slots; for (int i = 0; i < slots.Length; ++i) { FieldCellSlot slot = slots[i]; if (slot.IsEmpty()) { array[count++] = slot; } } return(count); }
public FieldCellArray(int width, int height) { this.width = width; this.height = height; slots = new FieldCellSlot[width * height]; int index = 0; for (int cy = 0; cy < height; ++cy) { for (int cx = 0; cx < width; ++cx) { slots[index++] = new FieldCellSlot(cx, cy); } } }
////////////////////////////////////////////////////////////////////////////// #region Bombs public void SetBomb(Bomb bomb) { AddCell(bomb); FieldCellSlot slot = GetSlot(bomb); PowerupCell powerup = slot.GetPowerup(); if (powerup != null) { powerup.RemoveFromField(); } else { FlameCell flame = slot.GetFlame(); if (flame != null) { bomb.Blow(); } } }
public PowerupCell GetPowerup(int cx, int cy) { FieldCellSlot slot = GetSlot(cx, cy); return(slot != null?slot.GetPowerup() : null); }
public BrickCell GetBrick(int cx, int cy) { FieldCellSlot slot = GetSlot(cx, cy); return(slot != null?slot.GetBrick() : null); }
////////////////////////////////////////////////////////////////////////////// public SolidCell GetSolid(int cx, int cy) { FieldCellSlot slot = GetSlot(cx, cy); return(slot != null?slot.GetSolid() : null); }
private int GetEmptySlots(FieldCellSlot[] array) { int count = 0; FieldCellSlot[] slots = cells.slots; for (int i = 0; i < slots.Length; ++i) { FieldCellSlot slot = slots[i]; if (slot.IsEmpty()) { array[count++] = slot; } } return count; }
public bool ContainsNoObstacle(int cx, int cy) { FieldCellSlot slot = GetSlot(cx, cy); return(slot != null && !slot.ContainsObstacle()); }
public bool HasNearObstacle(int dcx, int dcy) { FieldCellSlot slot = GetNearSlot(dcx, dcy); return(slot == null || slot.ContainsObstacle()); }
public bool HasNearObstacle(Direction dir) { FieldCellSlot slot = GetNearSlot(dir); return(slot == null || slot.ContainsObstacle()); }
private void ShuffleSlots(FieldCellSlot[] array, int size) { ArrayUtils.Shuffle(array, size); }
public FlameCell GetFlame(int cx, int cy) { FieldCellSlot slot = GetSlot(cx, cy); return(slot != null?slot.GetFlame() : null); }
public Bomb GetBomb(int cx, int cy) { FieldCellSlot slot = GetSlot(cx, cy); return(slot != null?slot.GetBomb() : null); }
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; }