Ejemplo n.º 1
0
 public void DestroyAll()
 {
     for (int i = Enemies.Count; i > 0; i--)
     {
         EnemyInstance enemy = Enemies[i - 1];
         enemy.Destroy();
         Enemies.Remove(enemy);
     }
 }
Ejemplo n.º 2
0
        //
        // Heat seeking
        //
        public ProjectileInstance(Projectile projectile, Vector3 sourcePos, EnemyInstance enemy, float waveTimeFired, LevelDescription desc)
        {
            LevelDesc      = desc;
            ProjectileType = projectile;
            LastUpdateTime = waveTimeFired;
            FireTime       = waveTimeFired;
#if LEVEL_EDITOR
            Position = new Vector3(sourcePos.X, PROJECTILE_HEIGHT, sourcePos.X);
#else
            Position = new Vector3(sourcePos.x, PROJECTILE_HEIGHT, sourcePos.z);
#endif
            Enemy      = enemy;
            IsComplete = false;
            go         = GameObjectFactory.InstantiateObject(ProjectileType.Asset);
            GameObjectFactory.SetMapPos(go, Position);
            heatSeeking = true;
        }
Ejemplo n.º 3
0
 void SpawnNewEnemies(float waveTime)
 {
     // Have we spawned all the enemies yet?
     // If not, are we due to spawn one or more enemies?
     while (SpawnedCount < Desc.Count)
     {
         float nextSpawnTime = LastSpawnTime + EnemyType.SpawnRate;
         if (waveTime > nextSpawnTime)
         {
             EnemyInstance newEnemy = new EnemyInstance(EnemyType, nextSpawnTime);
             newEnemy.UpdatePosition(LevelDesc);
             Enemies.Add(newEnemy);
             LastSpawnTime = nextSpawnTime;
             SpawnedCount++;
         }
         else
         {
             break;
         }
     }
 }
Ejemplo n.º 4
0
        bool AdvanceEnemyPositionsAndReportIfAnyActive(float waveTime)
        {
            bool isActive = false;

            for (int i = 0; i < Enemies.Count; i++)
            {
                EnemyInstance enemy = Enemies[i];
                if (enemy.IsActive)
                {
                    float timeSinceLastTick     = waveTime - enemy.LastMoveTime;
                    float progressSinceLastTick = timeSinceLastTick * enemy.Desc.MovementSpeed;
                    if (enemy.SpeedSlowdown > progressSinceLastTick)
                    {
                        progressSinceLastTick = 0.0F;
                    }
                    else
                    {
                        progressSinceLastTick -= enemy.SpeedSlowdown;
                    }
                    float newPosition = enemy.LinearProgress + progressSinceLastTick;
                    if (newPosition > (float)RoadSegments)
                    {
                        enemy.LinearProgress    = (float)RoadSegments;
                        enemy.ReachedFinishLine = true;
                        LivesLostToReport++;
                    }
                    else
                    {
                        enemy.LinearProgress = newPosition;
                    }
                    enemy.UpdatePosition(LevelDesc);
                    enemy.LastMoveTime = waveTime;
                    isActive           = true;
                }
            }

            return(isActive);
        }
Ejemplo n.º 5
0
        void ApplyProjectileEffects(float waveTime)
        {
            for (int i = 0; i < Enemies.Count; i++)
            {
                EnemyInstance enemy = Enemies[i];

                if (!enemy.IsActive)
                {
                    continue;
                }

                float damage   = 0.0F;
                float slowdown = 0.0F;

                for (int j = enemy.ActiveEffects.Count; j > 0; j--)
                {
                    EffectInstance effect = enemy.ActiveEffects[j - 1];

                    float impact = effect.AdvanceAndReportImpact(waveTime);

                    switch (effect.Effect.EffectType)
                    {
                    case ProjectileEffectType.Damage:
                        damage += impact;
                        break;

                    case ProjectileEffectType.Slow:
                        slowdown += impact;
                        break;
                    }


                    if (effect.Completed)
                    {
                        effect.Destroy();
                        enemy.ActiveEffects.Remove(effect);
                        effect = null;
                    }
                }

                if (null != DamageCallback)
                {
                    DamageCallback.Invoke(enemy, damage);
                }
                else
                {
                    if (enemy.HealthRemaining <= damage)
                    {
                        // Enemy is dead
                        enemy.HealthRemaining = 0.0F;
                        enemy.Destroy();
                        CoinEarnedToReport += enemy.Desc.Coins;
                    }
                    else
                    {
                        enemy.HealthRemaining -= damage;
                    }
                }

                enemy.SpeedSlowdown = slowdown;
            }
        }