示例#1
0
        public void Init(Vector2 dir, AsteroidData asteroidData)
        {
            this.AsteroidData = asteroidData;
            _moveDirection    = dir;
            _moveSpeed        = Random.Range(asteroidData.minSpeed, asteroidData.maxSpeed);
            healthComponent.RefillLive(GameEntityTag.UNKNOWN);

            _currentVelocity = _moveDirection * _moveSpeed;
        }
示例#2
0
        public async UniTask SpawnAsteroid(AsteroidData asteroidData, Vector2 moveDirection, Vector2 spawnPos)
        {
            GameObject asteroidGO = await _multiplePrefabMemoryPool.SpawnObject(GetRandomAsteroidPrefab(asteroidData).gameObject, spawnPos);

            var asteroid = asteroidGO.GetComponent <AsteroidComponent>();

            asteroid.Init(moveDirection, asteroidData);

            _spawnedAsteroids.Add(asteroid);

            _gameSignals.AsteroidSpawnedSignal.Fire(asteroid);
        }
示例#3
0
        public async UniTask SpawnAsteroidAtOutOfScreenPosition(AsteroidData asteroidData)
        {
            bool isMinHorizontal = Random.Range(0, 2) == 0;
            bool isMinVertical   = Random.Range(0, 2) == 0;

            Vector2 baseSpawnPos = Vector2.zero;

            baseSpawnPos.x = (isMinHorizontal) ? minWorldPos.x : maxWorldPos.x;
            baseSpawnPos.y = (isMinVertical) ? minWorldPos.y : maxWorldPos.y;

            Vector2 additionalPos = Vector2.zero;

            additionalPos.x = Random.Range(minAdditionalWorldPos.x, maxAdditionalWorldPos.x);
            additionalPos.y = Random.Range(minAdditionalWorldPos.y, maxAdditionalWorldPos.y);

            Vector2 spawnPos = baseSpawnPos;

            if (isMinHorizontal)
            {
                spawnPos.x -= additionalPos.x;
            }
            else
            {
                spawnPos.x += additionalPos.x;
            }

            if (isMinVertical)
            {
                spawnPos.y -= additionalPos.y;
            }
            else
            {
                spawnPos.y += additionalPos.y;
            }

            float   speed         = Random.Range(1f, 10f);
            Vector2 moveDirection = new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f));

            if (!isMinHorizontal)
            {
                moveDirection.x *= -1;
            }
            if (!isMinVertical)
            {
                moveDirection.y *= -1;
            }

            await SpawnAsteroid(asteroidData, moveDirection, spawnPos);
        }
示例#4
0
        private void SpawnWave()
        {
            _bookKeepingInGameData.AsteroidCount.Value = 0;

            var currentStageWave = _asteroidAssetSource.GetStageWaveData(_bookKeepingInGameData.CurrentStage.Value);

            if (currentStageWave == null)
            {
                throw new System.NullReferenceException($"Stage Wave Data null on stage {_bookKeepingInGameData.CurrentStage.Value}");
            }

            int asteroidTypeCount = currentStageWave.SpawnAsteroidDataList.Count;

            for (int i = 0; i < asteroidTypeCount; i++)
            {
                int          spawnCount   = Random.Range(currentStageWave.SpawnAsteroidDataList[i].MinSpawnCount, currentStageWave.SpawnAsteroidDataList[i].MaxSpawnCount + 1);
                AsteroidData asteroidData = _asteroidAssetSource.GetAsteroidData(currentStageWave.SpawnAsteroidDataList[i].AsteroidID);
                for (int j = 0; j < spawnCount; j++)
                {
                    _asteroidSpawnerSystem.SpawnAsteroidAtOutOfScreenPosition(asteroidData);
                }
            }
        }
示例#5
0
        public AsteroidComponent GetRandomAsteroidPrefab(AsteroidData asteroidData)
        {
            int randomIndex = Random.Range(0, asteroidData.prefabVariants.Length);

            return(asteroidData.prefabVariants[randomIndex]);
        }