Beispiel #1
0
        private void SpawnBomb()
        {
            float rarityRatio = Random.Range(0f, 1f);
            float rarityIndex = 0;

            foreach (var pair in _bombsRarity)
            {
                if (pair.Key < rarityRatio && pair.Key > rarityIndex)
                {
                    rarityIndex = pair.Key;
                }
            }

            int        bombIndex  = _bombsRarity[rarityIndex];
            BombConfig bombConfig = _configStorage.Get <BombConfig>(bombIndex);
            Vector3    position   = new Vector3(Random.Range(_spawnArea.xMin, _spawnArea.xMax), 45,
                                                Random.Range(_spawnArea.yMin, _spawnArea.yMax));

            BombModel      bomb           = new BombModel(bombConfig, position, this);
            BombController bombController = _controllerFactor.Create(bomb);

            bombController.transform.SetParent(_container, true);
            _bombs[bomb] = bombController;

            if (MaxSCount < _bombs.Count)
            {
                MaxSCount = _bombs.Count;
            }
            Debug.Log($"{_bombs.Count}/{MaxSCount}");
        }
Beispiel #2
0
    private bool ExplodeCell(Vector3Int relativePos, BombConfig bombConfig, AgentController bomber, bool isFirstRow = false)
    {
        Vector3 pos = tilemap.GetCellCenterWorld(relativePos);

        Tile tile = tilemap.GetTile <Tile>(relativePos);

        if (tile == wallTile)
        {
            return(false);
        }
        Collider2D collider = Physics2D.OverlapPoint(pos, LayerMask.GetMask("Bomb"));

        if (collider != null && !isFirstRow)
        {
            if (collider.tag == "Bomb")
            {
                collider.gameObject.GetComponent <Bomb>().SetCountdown(bombConfig.timeBeteweenExplosions);
            }
            return(false);
        }


        GameObject newExplosion = GetExplosion(pos);

        // mapController.AddNewExplosionToMap(cellPos, bomber);
        gameController.AddExplosion(newExplosion, relativePos, bomber);

        if (tile == destructibleTile)
        {
            tilemap.SetTile(relativePos, null);
            //mapController.CreateNewItem(cellPos);
            //newExplosion.GetComponent<Explosion>().SetConfigs(mapController, cellPos, true);
            return(false);
        }

        //newExplosion.GetComponent<Explosion>().SetConfigs(mapController, cellPos);

        return(true);
    }
Beispiel #3
0
    public void Explode(Vector2 worldPos, BombType bomb, AgentController bomber)
    {
        //int initialMatchId = gameController.matchId;
        Vector3Int originCell = tilemap.WorldToCell(worldPos);
        BombConfig bombConfig = AllEnviromentCommon.Instance.GetBombConfigs(bomb);
        int        radius     = bombConfig.radius;

        ExplodeCell(originCell, bombConfig, bomber, true);
        foreach (var direction in directions)
        {
            for (int i = 1; i < radius + 1; i++)
            {
                /*if (initialMatchId != gameController.matchId) {
                 *  return;
                 * }*/
                if (!ExplodeCell(originCell + i * direction, bombConfig, bomber))
                {
                    break;
                }
            }
        }
    }
Beispiel #4
0
 public BombModel(BombConfig config, Vector3 position, IBombEventHandler eventHandler)
 {
     _eventHandler = eventHandler;
     Config        = config;
     Position      = position;
 }