Пример #1
0
        public void Initialize(Vector2 startLocation)
        {
            IsDisposed = false;
            Location   = startLocation;

            if (Maths.Chance(50))
            {
                Direction = 1;
            }
            else
            {
                Direction = -1;
            }

            if (Maths.Chance(50) || Level.Instance.MGCnt == Level.MAX_MG_CNT)
            {
                Boom1 bm = Level.Instance.BoomPool.New();
                bm.Initialize(new Vector2(Animation.Width / 2 - 9, Animation.Height / 2), null);
                Guns.Add(bm);
            }
            else
            {
                MG1 mg = Level.Instance.MGPool.New();
                mg.Initialize(new Vector2(Animation.Width / 2 - 4 - 10, Animation.Height), new Vector2(Animation.Width / 2 - 4 + 10, Animation.Height), null);
                Guns.Add(mg);
                Level.Instance.MGCnt++;
            }
        }
        /// <summary>
        /// Call this after getting me from the pool.
        /// </summary>
        /// <param name="startLoc"></param>
        public void Initialize(Vector2 startLoc)
        {
            IsDisposed = false;
            Location   = startLoc;

            int  rndWpn;
            bool pass;

            do
            {
                pass   = true;
                rndWpn = Maths.RandomNr(1, 100);
                if (rndWpn < 30)
                {
                    AutoAim aa = Level.Instance.AutoAimPool.New();
                    aa.Initialize(new Vector2(Animation.Width / 2 - 8, Animation.Height / 2 - 8), null);
                    Guns.Add(aa);
                    Velocity = 2.4f;
                }
                else if (rndWpn < 70)
                {
                    Boom1 bm = Level.Instance.BoomPool.New();
                    bm.Initialize(new Vector2(Animation.Width / 2 - 9, Animation.Height / 2), null);
                    Guns.Add(bm);
                    Velocity = 3f;
                }
                else
                {
                    if (Level.Instance.MGCnt < Level.MAX_MG_CNT)
                    {
                        Level.Instance.MGCnt++;
                        Velocity = 3f;
                        MG1 mg = Level.Instance.MGPool.New();
                        mg.Initialize(new Vector2(Animation.Width / 2 - 4 - 10, Animation.Height), new Vector2(Animation.Width / 2 - 4 + 10, Animation.Height), null);
                        Guns.Add(mg);
                    }
                    else
                    {
                        pass = false;
                    }
                }
            } while (!pass);
        }
        public void AddGun(eEnemyGunType gunType)
        {
            switch (gunType)
            {
            case eEnemyGunType.AutoAim:
                AutoAim aa = Level.Instance.AutoAimPool.New();
                aa.Initialize(new Vector2(Animation.Width / 2 - 8, Animation.Height / 2 - 8), Owner);
                Guns.Add(aa);
                break;

            case eEnemyGunType.Boom1Enemy:
                Boom1 b = Level.Instance.BoomPool.New();
                b.Initialize(new Vector2(Animation.Width / 2 - 9, 0), Owner);
                Guns.Add(b);
                break;

            case eEnemyGunType.MG1:
                throw new Exception("MG Can not be added");

            case eEnemyGunType.Missile:
                Missile m = Level.Instance.MissilePool.New();
                m.Initialize(new Vector2(Animation.Width / 2 - 9, Animation.Height / 2 - 11), Owner);
                Guns.Add(m);
                break;

            case eEnemyGunType.DualMissile45:
                DualMissile45 dm = Level.Instance.DualMissile45Pool.New();
                dm.Initialize(new Vector2(Animation.Width / 2 - 11, 5), Owner);
                Guns.Add(dm);
                break;

            default:
                throw new CaseStatementMissingException();
            }
            UpdateAquiredGuns();
        }
Пример #4
0
        public Level(int startingWave, int dropRateModifier, int waveDelayInMS, int area, float scoreModifier, string music, ePlaneType planeType, string shipName)
        {
            // Music
            Music = music;
            MP3MusicMgr.Instance.PlayMusic(music);

            ScoreModifier           = scoreModifier;
            WaveNr                  = startingWave;
            ItemEnemy.LastWaveSpawn = WaveNr;
            DropRateModifier        = dropRateModifier;
            SpawnDelayTimer         = new SimpleTimer(waveDelayInMS);
            ScrollBG                = new ScrollBG("bg0" + area.ToString());
            Shop.IsFirstVisit       = true;
            if (area == 3 || area == 4)
            {
                MG1.MGDrawColor = Color.DarkRed;
                MG2.MGDrawColor = Color.DarkBlue;
            }
            else
            {
                MG1.MGDrawColor = MG2.MGDrawColor = Color.White;
            }
            WaveNrSB = new StringBuilder(startingWave.ToString(), 2);

            BroadPhase.Instance = new BroadPhase(128);
            BroadPhase.Instance.Init();

            Level.Instance = this;
            #region Generic Pools
            MGPool            = new Pool <MG1>(25, true, g => !g.IsDisposed, () => MG1.PoolConstructor());
            MG2Pool           = new Pool <MG2>(1, true, g => !g.IsDisposed, () => MG2.PoolConstructor());
            AutoAimPool       = new Pool <AutoAim>(100, true, g => !g.IsDisposed, () => AutoAim.PoolConstructor());
            BoomPool          = new Pool <Boom1>(100, true, g => !g.IsDisposed, () => Boom1.PoolConstructor());
            MissilePool       = new Pool <Missile>(80, true, g => !g.IsDisposed, () => Missile.PoolConstructor());
            DualMissile45Pool = new Pool <DualMissile45>(80, true, g => !g.IsDisposed, () => DualMissile45.PoolConstructor());
            // Enemies
            StraightEnemyPool = new Pool <StraightEnemy>(200, true, e => !e.IsDisposed, () => StraightEnemy.PoolConstructor());
            SuiciderEnemyPool = new Pool <SuiciderEnemy>(60, true, e => !e.IsDisposed, () => SuiciderEnemy.PoolConstructor());
            ItemEnemyPool     = new Pool <ItemEnemy>(10, true, e => !e.IsDisposed, () => ItemEnemy.PoolConstructor());
            ZigZagEnemyPool   = new Pool <ZigZagEnemy>(130, true, e => !e.IsDisposed, () => ZigZagEnemy.PoolConstructor());
            BombardEnemyPool  = new Pool <BombardEnemy>(60, true, e => !e.IsDisposed, () => BombardEnemy.PoolConstructor());
            Dual45EnemyPool   = new Pool <Dual45Enemy>(60, true, e => !e.IsDisposed, () => Dual45Enemy.PoolConstructor());
            SideEnemyPool     = new Pool <SideEnemy>(10, true, e => !e.IsDisposed, () => SideEnemy.PoolConstructor());
            // Explosions
            ExplosionPool = new Pool <Visual>(100, true, v => !v.IsDisposed, () => Visual.PoolConstructor());
            // Scrap station
            ScrapStationPool = new Pool <ScrapStation>(2, true, s => !s.IsDisposed, () => ScrapStation.PoolConstructor());
            #endregion

            Players.Add(new Player());

            // Projectile pool
            for (int i = 0; i < PROJECTILE_POOL_MAX; i++)
            {
                ProjectilePool.Add(new BaseProjectile());
            }

            // Pickup pool
            for (int i = 0; i < PICKUP_MAX; i++)
            {
                PickupPool.Add(new Pickup());
            }

            // Increase the spawn delay every 5 waves
            int spawnDelayIncs = WaveNr / 5;
            for (int i = 0; i < spawnDelayIncs; i++)
            {
                SpawnDelayTimer.TimeInMS += SPAWN_DELAY_INCREASE;
            }

            // Add starting resources
            for (int i = 1; i <= startingWave; i++)
            {
                if (i < 5)
                {
                    for (int j = 0; j < Players.Count; j++)
                    {
                        Players[j].Score += 150;
                    }
                }
                else
                {
                    for (int j = 0; j < Players.Count; j++)
                    {
                        Players[j].Score += 500;
                    }
                }
                // Limit score to ~15000
                if (Players[0].Score >= 15000)
                {
                    break;
                }
            }

            // Spawn scrap station if starting wave # >=20
            if (startingWave >= 20)
            {
                SpawnScrapStation();
            }

            #region Player
            PlayerShip ps = new PlayerShip(PlayerIndex.One, new Vector2(500, 400), Players[0]);
            ps.SetPlaneType(planeType, shipName);

            // Bonus speed & shield regen
            int bonusSpeedUpgrades = startingWave / 10;
            for (int i = 0; i < bonusSpeedUpgrades; i++)
            {
                ps.UpgradeSpeed();
                ps.UpgradeShieldRegen();
            }
            // Add mg
            MG1 mg = MGPool.New();
            mg.Initialize(new Vector2(5, ps.Height - 20), new Vector2(ps.Width - 5 - 8, ps.Height - 20), ps.Owner);
            ps.Guns.Add(mg);

            Entities.Add(ps);
            PlayerShips.Add(ps);
            #endregion

            // Pause
            PauseLocation = Common.CenterString(PausedFont, PAUSE_TEXT, Engine.Instance.Width, Engine.Instance.Height);

            // Collect Garbage
            System.GC.Collect();
        }