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 HandleCollision(PowerupCell cell) { int powerup = cell.powerup; TryAddPowerup(powerup); cell.RemoveFromField(); return(true); }
void GenerateCells() { int rows = this.rows; int cols = this.cols; m_cells = new Cell[rows, cols]; m_Width = cols * Constants.CELL_WIDTH; m_Height = rows * Constants.CELL_HEIGHT; for (int i = 0; i < rows; ++i) { for (int j = 0; j < cols; ++j) { var tile = m_tileMap.GetTile(j, i); if (tile != null) { Cell cell = null; if (tile == m_tiles[CELL_GROUND] || tile == m_tiles[CELL_SOLID] || tile == m_tiles[CELL_BLANK] || tile == m_tiles[CELL_TUBE1] || tile == m_tiles[CELL_TUBE2] || tile == m_tiles[CELL_TUBE_TOP1] || tile == m_tiles[CELL_TUBE_TOP2]) { cell = new Cell(this, i, j); } else if (tile is HittableTile) { var hittableTile = tile as HittableTile; if (hittableTile.type == HittableTileType.Empty) { cell = new BrickCell(this, i, j); } else if (hittableTile.type == HittableTileType.Mushroom) { cell = new PowerupCell(this, i, j, PowerupType.Mushroom); } else if (hittableTile.type == HittableTileType.Coins) { cell = new CoinsCell(this, i, j, hittableTile.cointCount); } else { Debug.LogWarning("Unexpected type: " + hittableTile.type); cell = new Cell(this, i, j); } } m_cells[i, j] = cell; } } } }
private void DrawPowerup(Context context, PowerupCell powerupCell) { int powerup = powerupCell.powerup; if (powerup != Powerups.None) { if (powerup == Powerups.Random) { powerup = ((int)(powerupCell.elasped / 0.05f)) % powerupImages.Length; } TextureImage image = powerupImages[powerup]; DrawCellImage(context, powerupCell, image); } }
private void WriteFieldState(NetBuffer buffer, Field field) { int bitsForPlayerIndex = NetUtility.BitsToHoldUInt((uint)(field.GetPlayers().GetCount() - 1)); FieldCellSlot[] slots = field.GetCells().slots; for (int i = 0; i < slots.Length; ++i) { FieldCell staticCell = slots[i].staticCell; bool shouldWrite = staticCell != null && !staticCell.IsSolid(); buffer.Write(shouldWrite); if (shouldWrite) { switch (staticCell.type) { case FieldCellType.Brick: { BrickCell brick = staticCell.AsBrick(); buffer.Write(CELL_BRICK, BITS_FOR_STATIC_CELL); break; } case FieldCellType.Powerup: { PowerupCell powerup = staticCell.AsPowerup(); buffer.Write(CELL_POWERUP, BITS_FOR_STATIC_CELL); buffer.Write(powerup.powerup, BITS_FOR_POWERUP); break; } case FieldCellType.Flame: { FlameCell flame = staticCell.AsFlame(); buffer.Write(CELL_FLAME, BITS_FOR_STATIC_CELL); buffer.Write(flame.player.GetIndex(), bitsForPlayerIndex); break; } } } } }
////////////////////////////////////////////////////////////////////////////// #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(); } } }