コード例 #1
0
    protected void _processSingleEnemySpawner(EnemySpawnerComponent enemySpawner, float deltaTime)
    {
        int currWaveIndex  = enemySpawner.mCurrWaveIndex;
        int currEnemyIndex = enemySpawner.mCurrEnemyIndex;

        if (!_waitForNextWave(enemySpawner, deltaTime))
        {
            return;
        }

        /// last wave and all enemies were destroyed
        if (currWaveIndex >= enemySpawner.mWavesArray.Count)
        {
            if (GetEntities <TEnemyGroup>().Length < 1)
            {
                EventBus.NotifyOnLevelFinished();
            }

            return;
        }

        Vector3 spawningPosition = enemySpawner.CachedTransform.position;

        GameObject currEnemyPrefab = null;

        WaveConfig currWaveConfig = null;

        /// time to spawn new enemy
        if (enemySpawner.mCurrSpawningTimer > enemySpawner.mSpawningInterval || currEnemyIndex == 0)
        {
            currWaveConfig = enemySpawner.mWavesArray[currWaveIndex];

            /// new waves should be started
            if (currEnemyIndex >= currWaveConfig.EnemiesCount)
            {
                currWaveIndex  = ++enemySpawner.mCurrWaveIndex;
                currEnemyIndex = 0;

                enemySpawner.mCurrEnemyIndex = 0;

                enemySpawner.mIsWaitingForNextWave = true;

                /// TODO: inform player about a new wave is incoming

                return;
            }

            currEnemyPrefab = enemySpawner.mWavesArray[currWaveIndex][currEnemyIndex];

            enemySpawner.mCurrEnemyIndex = currEnemyIndex + 1;

            _spawnNewEnemy(currEnemyPrefab, spawningPosition, enemySpawner.mStartWaypoint);

            /// reset spawning timer
            enemySpawner.mCurrSpawningTimer = 0.0f;
        }

        enemySpawner.mCurrSpawningTimer += deltaTime;
    }
    public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
    {
        var spawnerData = new EnemySpawnerComponent
        {
            smallRock  = conversionSystem.GetPrimaryEntity(smallRock),
            medRock    = conversionSystem.GetPrimaryEntity(medRock),
            bigRock    = conversionSystem.GetPrimaryEntity(bigRock),
            enemyShipA = conversionSystem.GetPrimaryEntity(enemyshipA)
        };

        dstManager.AddComponentData(entity, spawnerData);
    }
コード例 #3
0
    public void Execute()
    {
        for (int i = 0; i < spawners.Length; ++i)
        {
            EnemySpawnerComponent enemySpawnerComponent = entityDatabase.CreateEntity().AddComponent <EnemySpawnerComponent>();;
            enemySpawnerComponent.spawnerData = spawners[i];
            enemySpawnerComponent.timer       = enemySpawnerComponent.spawnerData.spawnTime;
        }

        Entity rootEntity = entityDatabase.QueryEntity(Tag.Root);

        rootEntity.AddComponent <ColliderComponentMap>();
    }
コード例 #4
0
    public void Update()
    {
        ListReadOnly <EnemySpawnerComponent> enemySpawnerComponents = entityDatabase.QueryTypes <EnemySpawnerComponent>();
        var enumerator = enemySpawnerComponents.GetEnumerator();

        while (enumerator.MoveNext())
        {
            EnemySpawnerComponent enemySpawnerComponent = enumerator.Current;
            enemySpawnerComponent.timer -= Time.deltaTime;

            if (enemySpawnerComponent.timer <= 0)
            {
                Spawn(enemySpawnerComponent.spawnerData);
                enemySpawnerComponent.timer = enemySpawnerComponent.spawnerData.spawnTime;
            }
        }
    }
コード例 #5
0
    void spawnIfCan(Entity e, Vector3 cameraPosition, DifficultyControllerComponent difficulty)
    {
        EnemySpawnerComponent enemySpawner = e.enemySpawner;
        XmlNode node = enemySpawner.node;

        if (enemySpawner.used && node != null)
        {
            enemySpawner.node = enemySpawner.node.NextSibling;
            node = enemySpawner.node;
        }
        if (node != null)
        {
            enemySpawner.used = false;
            XmlAttributeCollection attributes = node.Attributes;
            float spawnBarrier = (float)Convert.ToDouble(attributes[0].Value);
            if (spawnBarrier < cameraPosition.y)
            {
                XmlNode innerNode = node.FirstChild;
                while (innerNode != null)
                {
                    int     enemyCount = Convert.ToInt16(innerNode.Attributes[0].Value);
                    Vector2 position   = new Vector2((float)Convert.ToDouble(innerNode.Attributes[1].Value),
                                                     (float)Convert.ToDouble(innerNode.Attributes[2].Value));
                    Vector2 velocity = new Vector2((float)Convert.ToDouble(innerNode.Attributes[3].Value),
                                                   (float)Convert.ToDouble(innerNode.Attributes[4].Value));
                    int type   = Convert.ToInt16(innerNode.Attributes[5].Value);
                    int health = Convert.ToInt16(innerNode.Attributes[6].Value) * (difficulty.hpBoostPercent + 100) / 100;
                    while (enemyCount != 0)
                    {
                        _factory.createEnemyByType(type, position, velocity, health, difficulty.missileSpeedBoostPercent);
                        enemyCount--;
                    }
                    innerNode = innerNode.NextSibling;
                }

                enemySpawner.used = true;
            }
        }
        else
        {
            // all enemies spawned
        }
    }
コード例 #6
0
    protected bool _waitForNextWave(EnemySpawnerComponent enemySpawner, float deltaTime)
    {
        /// don't start timer because a previous wave is still coming
        if (!enemySpawner.mIsWaitingForNextWave)
        {
            return(true);
        }

        if (enemySpawner.mCurrPerWaveRestTimer < enemySpawner.mPerWaveRestInterval)
        {
            enemySpawner.mCurrPerWaveRestTimer += deltaTime;

            return(false);
        }

        EventBus.NotifyOnNewWaveIsComing(enemySpawner.mCurrWaveIndex + 1);         // a first displaying index will be 1 instead of 0

        enemySpawner.mIsWaitingForNextWave = false;

        enemySpawner.mCurrPerWaveRestTimer = 0.0f;

        return(true);
    }