protected void ReadFieldState(NetBuffer buffer)
        {
            // bricks & powerups
            FieldCellSlot[] slots = game.Field.GetCells().slots;
            for (int i = 0; i < slots.Length; ++i)
            {
                BrickCell brick = slots[i].GetBrick();
                if (brick != null)
                {
                    bool hasPowerup = buffer.ReadBoolean();
                    if (hasPowerup)
                    {
                        brick.powerup = buffer.ReadByte();
                    }
                }
            }

            // players
            int senderIndex  = buffer.ReadByte();
            int playersCount = buffer.ReadByte();

            for (int i = 0; i < playersCount; ++i)
            {
                Player player = new Player(i);
                int    cx     = buffer.ReadByte();
                int    cy     = buffer.ReadByte();
                player.SetCell(cx, cy);
                if (i != senderIndex)
                {
                    player.SetPlayerInput(new PlayerNetworkInput());
                }

                game.AddPlayer(player);
            }
        }
        protected void WriteFieldState(NetBuffer buffer, Player player)
        {
            // bricks & powerups
            FieldCellSlot[] slots = game.Field.GetCells().slots;
            for (int i = 0; i < slots.Length; ++i)
            {
                BrickCell brick = slots[i].GetBrick();
                if (brick != null)
                {
                    bool hasPowerup = brick.HasPowerup();
                    buffer.Write(hasPowerup);
                    if (hasPowerup)
                    {
                        buffer.Write((byte)brick.powerup);
                    }
                }
            }

            // players
            List <Player> players = game.GetPlayers().list;

            int senderIndex = players.IndexOf(player);

            Debug.Assert(senderIndex != -1);

            buffer.Write((byte)senderIndex);
            buffer.Write((byte)players.Count);
            for (int i = 0; i < players.Count; ++i)
            {
                Player p = players[i];
                buffer.Write((byte)p.cx);
                buffer.Write((byte)p.cy);
            }
        }
Example #3
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);
        }
Example #4
0
    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;
                }
            }
        }
    }
Example #5
0
 private void ClearBrick(int cx, int cy)
 {
     if (IsInsideField(cx, cy))
     {
         BrickCell brick = GetBrick(cx, cy);
         if (brick != null)
         {
             RemoveCell(brick);
         }
     }
 }
Example #6
0
        public void DestroyBrick(BrickCell brick)
        {
            brick.RemoveFromField();

            int powerup = brick.powerup;

            if (powerup != Powerups.None)
            {
                int cx = brick.GetCx();
                int cy = brick.GetCy();
                AddCell(new PowerupCell(powerup, cx, cy));
            }
        }
Example #7
0
        private void DrawBrick(Context context, BrickCell cell)
        {
            DrawCellImage(context, cell, breakableImage);

            if (CVars.g_drawHiddenPowerups.boolValue)
            {
                int powerup = cell.powerup;
                if (powerup != Powerups.None)
                {
                    TextureImage powerupImage = powerupImages[powerup];
                    float        drawX        = cell.GetPx() - 0.5f * powerupImage.GetWidth();
                    float        drawY        = cell.GetPy() - 0.5f * powerupImage.GetHeight();
                    context.DrawImage(powerupImage, drawX, drawY, 0.25f);
                }
            }
        }
Example #8
0
        private int GetBrickCells(BrickCell[] array)
        {
            int count = 0;

            FieldCellSlot[] slots = cells.slots;
            foreach (FieldCellSlot slot in slots)
            {
                BrickCell brickCell = slot.GetBrick();
                if (brickCell != null)
                {
                    if (brickCell.powerup == Powerups.None)
                    {
                        array[count++] = brickCell;
                    }
                }
            }

            return(count);
        }
        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;
                    }
                    }
                }
            }
        }
Example #10
0
        private void SetupPowerups(PowerupInfo[] powerupInfo)
        {
            foreach (PowerupInfo info in powerupInfo)
            {
                if (info.bornWith)
                {
                    List <Player> playerList = players.list;
                    foreach (Player player in playerList)
                    {
                        player.TryAddPowerup(info.powerupIndex);
                    }
                }
            }

            BrickCell[] brickCells = new BrickCell[GetWidth() * GetHeight()];
            int         count      = GetBrickCells(brickCells);

            if (count == 0)
            {
                return;
            }

            ShuffleCells(brickCells, count);

            CVar[] POWERUPS_COUNT = CVars.powerupsCount;

            int brickIndex = 0;

            foreach (PowerupInfo info in powerupInfo)
            {
                if (info.forbidden || info.bornWith)
                {
                    continue;
                }

                int powerupIndex = info.powerupIndex;
                int powerupCount = POWERUPS_COUNT[powerupIndex].intValue;
                if (powerupCount < 0)
                {
                    if (MathHelp.NextInt(10) < -powerupCount)
                    {
                        continue;
                    }
                    powerupCount = 1;
                }

                for (int i = 0; i < powerupCount; ++i)
                {
                    BrickCell cell = brickCells[brickIndex++];
                    int       cx   = cell.GetCx();
                    int       cy   = cell.GetCy();

                    cell.powerup = powerupIndex;

                    if (brickIndex == count)
                    {
                        break;
                    }
                }

                if (brickIndex == count)
                {
                    break;
                }
            }
        }