Exemplo n.º 1
0
        public void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            Players.ForEach(p => p.Update(gameTime, elapsed));
            Projectiles.ForEach(p => p.Update(gameTime, elapsed));
            Projectiles.RemoveAll(p => p.IsDisposed);

            // Enemies
            if (BonusEnemy != null)
            {
                BonusEnemy.Update(gameTime, elapsed);
                if (BonusEnemy.IsDisposed)
                {
                    BonusEnemy = null;
                }
            }
            Enemies.ForEach(e => e.Update(gameTime, elapsed));
            Enemies.RemoveAll(e => e.IsDisposed);
            if (Enemies.Any(e => e.ReachedEndOfScreen))
            {
                Enemies.ForEach(e => e.TurnAround());
            }

            // Bonus
            if (!BonusAppearedThisRound && ShotCnt >= ShotsForBonus)
            {
                BonusAppearedThisRound = true;
                BonusEnemy             = new BonusEnemy();
            }

            // Next level check/handling
            if (Enemies.Count == 0 && BonusEnemy == null)
            {
                NextLevel(LevelNr);
            }

            // Gameover check/handling
            if (!Players.Any(p => p.IsAlive) || Enemies.Any(e => e.CollisionRect.Bottom >= DEAD_LINE))
            {
                GameOver();
            }

            // Music
            if (InputMgr.Instance.IsPressed(null, Keys.M, Buttons.RightShoulder))
            {
                Engine.Instance.Audio.PlayMusic("music", true);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Proceeds to game to the next level
        /// </summary>
        /// <param name="currentLvlNr"></param>
        public void NextLevel(int currentLvlNr)
        {
            LevelNr = currentLvlNr + 1;

            #region Clear
            Enemies.Clear();
            Projectiles.Clear();
            BonusEnemy = null;
            #endregion

            #region Bonus
            ShotsForBonus          = Maths.RandomNr(15, 23); // Sets the amount of shots needed before the bonus appears
            BonusAppearedThisRound = false;
            ShotCnt = 0;
            #endregion

            // Heal the Walls
            Walls.ForEach(w => w.Heal());

            // Set random background
            BG = Common.str2Tex("BG/invaderBG0" + Maths.RandomNr(1, 3));

            #region Load the enemies
            for (int x = 0; x < 11; x++)
            {
                Enemies.Add(new Enemy(LevelNr, new Vector2(100 + x * (Enemy.WIDTH + ENEMY_SPACING_X), ENEMY_OFFSET_TOP), eEnemyType.Top));
            }
            for (int x = 0; x < 11; x++)
            {
                for (int y = 1; y < 3; y++)
                {
                    Enemies.Add(new Enemy(LevelNr, new Vector2(100 + x * (Enemy.WIDTH + ENEMY_SPACING_X), ENEMY_OFFSET_TOP + y * (ENEMY_SPACING_Y + Enemy.HEIGHT)), eEnemyType.Mid));
                }
            }
            for (int x = 0; x < 11; x++)
            {
                for (int y = 3; y < 5; y++)
                {
                    Enemies.Add(new Enemy(LevelNr, new Vector2(100 + x * (Enemy.WIDTH + ENEMY_SPACING_X), ENEMY_OFFSET_TOP + y * (ENEMY_SPACING_Y + Enemy.HEIGHT)), eEnemyType.Bottom));
                }
            }
            #endregion

            // Clean up
            GC.Collect();
        }