Exemple #1
0
    public override void Update(object gameTime)
    {
        base.Update(gameTime);
        if (GameStats.InWave)
        {
            if (RANDOM.Next(50) == 0 && resources > 0)
            {
                double   type_a = Math.Sqrt(Math.Min(LIST_ENEMIES.Count, (int)(GameStats.Wave / 3)));
                double   type_b = Math.Sqrt(Math.Min(LIST_ENEMIES.Count, (int)(GameStats.Wave / 3)));
                string   eType  = LIST_ENEMIES[RANDOM.Next((int)(type_a * type_b))];
                Type     t      = Type.GetType(eType);         //Get the type of the object
                object   temp   = Activator.CreateInstance(t); //Create an instance of that object
                Enemy    obj    = temp as Enemy;               //Cast it as an Enemy
                GridNode node   = available[RANDOM.Next(available.Count)];

                obj.startNode = node;
                obj.Position  = node.Position;
                plane.Add(obj);
                resources -= obj.cost;
            }

            bool         AllDeath = true;
            List <Enemy> list     = plane.FindByType <Enemy>();
            foreach (Enemy e in list)
            {
                if (!e.kill)
                {
                    AllDeath = false;
                    break;
                }
            }
            if (AllDeath && GameStats.InWave && resources <= 0)
            {
                GameStats.InWave    = false;
                GameStats.WaveTimer = 10 * 60;
            }
        }

        if (!GameStats.InWave && GameStats.WaveTimer > 0)
        {
            GameStats.WaveTimer--;
            if (GameStats.WaveTimer <= 0)
            {
                GameStats.InWave = true;
                int x = GameStats.Wave++;

                resources = (int)(500 + 2 * Math.Pow(x, (Math.Sqrt(x / 100) + 1)) + 400 * (float)Math.Sqrt(x));
            }
        }
    }