private IntVector2 GetRandomMushroomPosition(IntVector2 gridSize)
    {
        IntVector2 pos = new IntVector2(Random.Range(1, gridSize.x - 1), Random.Range(1, gridSize.y - 1));

        if (_levelManager.IsCellOccupiedByMushroom(pos) || _levelManager.IsCellOccupiedBySpider(pos))
        {
            pos = GetRandomMushroomPosition(gridSize);
        }

        return(pos);
    }
Esempio n. 2
0
    public void Update()
    {
        if (_bullet == null || !_bullet.gameObject.activeSelf)
        {
            return;
        }

        if (_canMove && Vector3.Distance(_bullet.position, _targetPosition) < 0.001f)
        {
            _canMove         = false;
            _targetPosition += Vector3.up;

            IntVector2 position = new IntVector2((int)_targetPosition.x, (int)_targetPosition.y);

            if (position.y >= _gridMaxHeight)
            {
                DestroyBullet();
                return;
            }

            if (_levelManager.IsCellOccupiedByMushroom(position))
            {
                DestroyBullet();
                _mushroomManager.DamageMushroomAtPosition(position, _damage);
                return;
            }

            if (_levelManager.IsCellOccupiedBySpider(position))
            {
                DestroyBullet();
                _spiderManager.DestroySpider(position);
                return;
            }

            if (_levelManager.IsCellOccupiedByCentipede(position))
            {
                DestroyBullet();
                _centipedeManager.DestroyBodyPart(position);
                return;
            }

            MainApp.Instance.StartCoroutine(Move(1f / _speed));
        }
    }