Beispiel #1
0
        public Explosion(GameManager gameManager, EnemySpawner es, EnemyMissile hostile, Vector2f spawnHere, Building hitBuilding, int setType)
        {
            gm = gameManager;
            ExplosionLocation        = spawnHere;
            ExplosionLocationTopLeft = new Vector2f(ExplosionLocation.X - Expl_size / 2f, ExplosionLocation.Y - Expl_size / 2f);
            enemySpawner             = es;
            type = setType;

            //Prevent out of range exception, in case the building is already destroyed
            try
            {
                nukeTown = gm.GetBuildings()[gm.GetBuildings().IndexOf(hitBuilding)];
            }
            catch (Exception e)
            {
                Console.WriteLine("===============================================");
                Console.WriteLine(string.Format("Error: {0}", e));
                Console.WriteLine(string.Format("Count: {0}, attemping to access {1}", gm.GetBuildings().Count, gm.GetBuildings().IndexOf(hitBuilding)));
                Console.WriteLine("===============================================");
                gm.error_reason     = e;
                Registers.gameState = GameState.Error;
            }
            rec_explosion.X = spawnHere.X;
            rec_explosion.Y = spawnHere.Y;
        }
        public override void Update()
        {
            if (Registers.gameState == GameState.Running)
            {
                timeLeft -= GAME_ENGINE.GetDeltaTime();
                if (timeLeft <= 0)
                {
                    int targ = rng.Next(0, targets.Count);
                    emis = new EnemyMissile(gameManager, this, new Vector2f(rng.Next(0, Registers.ScreenWidth), 0), targets[targ], targ);
                    emissiles.Add(emis);

                    //60% chance a second missile will spawn
                    if (Utils.Chance(60))
                    {
                        int targSec = rng.Next(0, targets.Count);
                        emis = new EnemyMissile(gameManager, this, new Vector2f(rng.Next(0, Registers.ScreenWidth), 0), targets[targSec], targSec);
                        emissiles.Add(emis);
                    }
                    //20% chance a third missile will spawn
                    if (Utils.Chance(20))
                    {
                        int targThr = rng.Next(0, targets.Count);
                        emis = new EnemyMissile(gameManager, this, new Vector2f(rng.Next(0, Registers.ScreenWidth), 0), targets[targThr], targThr);
                        emissiles.Add(emis);
                    }
                    timeLeft = interval;
                }
            }
        }
 public void EMissileDetonate(EnemyMissile detEMissile)
 {
     detEMissile.explM = new Explosion(gameManager, this, detEMissile, detEMissile.GetLocation(), gameManager.GetBuildings()[detEMissile.targetID], 0);
     Console.WriteLine("Demontated missile");
     if (emissiles.Contains(detEMissile))
     {
         detEMissile.Dispose();
         emissiles.Remove(detEMissile);
     }
     return;
 }