Exemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            if (ActiveWave.IsDone)
            {
                if (WaveIndex >= WaveList.Count - 1)
                {
                    if (Endless)
                    {
                        WaveIndex = 0;
                    }
                    else
                    {
                        State = MapState.Finished;
                    }
                }

                if (State != MapState.Finished)
                {
                    if (WaveDelay > 0)
                    {
                        Timer = WaveDelay;
                        State = MapState.WaveDelay;
                    }
                    WaveIndex++;
                    ActiveWave = WaveList[WaveIndex];

                    if (NewWave != null)
                    {
                        NewWave(this, EventArgs.Empty);
                    }
                }
            }
            else
            {
                if (Timer > 0)
                {
                    Timer -= (float)gameTime.ElapsedGameTime.TotalSeconds * Session.singleton.Speed;
                }
                else
                {
                    if (State == MapState.WaveDelay)
                    {
                        State = MapState.Active;
                    }

                    ActiveWave.Update(gameTime);
                }
            }
        }
Exemplo n.º 2
0
    /// <summary>
    ///  Spawn an enemy object inside the bounds of the Collider that is
    /// attached to This gameobject.
    /// </summary>
    /// <param name="toSpawn"> Override Wave's pool pick with user's prefered pool. </param>
    public virtual IEnumerator Spawn(ObjectPool toSpawn = null, int numberOfSpawns = -1) {
        toSpawn = (toSpawn == null) ? ActiveWave.PickRandomPool() : toSpawn;
        numberOfSpawns = (numberOfSpawns == -1) ? ActiveWave.ObjectsPerSpawn : numberOfSpawns;
        for (int i = 0; i < numberOfSpawns; i++) {
            var spawned = toSpawn.SpawnAt(GetRandomPosition(_boxCollider.bounds));
            if(spawned == null) { //happenes when there are no more available objects in to spawn in the pool
                continue;
            }
            EMeteor meteor = spawned.GetComponent<EMeteor>();
            if (meteor) {
                meteor.SetDirection(GetPositionToMoveTowards());
            }

            float waitTime = Random.Range(2, 6) / 10.0f;
            if (numberOfSpawns == 1) //Don't waste cicles on 1 object per spawn.
                waitTime = 0.0f;
            yield return new WaitForSeconds(waitTime);
        }//for
    }//Spawn