コード例 #1
0
        public override void Update(GameTime gameTime)
        {
            player.Update(gameTime, Game.Window.ClientBounds);

            //  Is the game finished?
            #region Look if game is finished
            if (player.Score <= -500)
            {
                _wonTheGame = false;
                this.ScreenManager.AddScreen(new EndScreen(Game, _wonTheGame));
                Unload();
            }
            if (player.Score >= 1000)
            {
                _wonTheGame = true;
                this.ScreenManager.AddScreen(new EndScreen(Game, _wonTheGame));
                Unload();
            }
            #endregion

            //  Spawning gems and enemies every MILLISECONDS_PER_SPAWN
            _millisecondsSinceLastSpawn += gameTime.ElapsedGameTime.Milliseconds;
            if (_millisecondsSinceLastSpawn >= MILLISECONDS_PER_SPAWN)
            {
                Spawn();
                _millisecondsSinceLastSpawn -= MILLISECONDS_PER_SPAWN;
            }

            foreach (var enemy in enemies.ToList())
            {
                //  Check if an enemy collides with the player
                if (enemy.HitBox.Intersects(player.HitBox))
                {
                    player.Collides(enemy);
                    //  The enemy needs to be destroyed
                    enemies.Remove(enemy);
                    continue;
                }
                enemy.Update(gameTime, Game.Window.ClientBounds);
                if (enemy.IsDestroyable())
                {
                    enemies.Remove(enemy);
                }
            }

            foreach (var stone in preciousStones.ToList())
            {
                //  Check if a stone is colliding with the player
                if (stone.HitBox.Intersects(player.HitBox))
                {
                    player.Collides(stone);
                    //  The stone needs to be removed
                    preciousStones.Remove(stone);

                    //  We continue the loop
                    continue;
                }

                //  If the stone is out of bounds, we delete it
                if (stone.HitBox.Y > Game.Window.ClientBounds.Height)
                {
                    preciousStones.Remove(stone);
                    continue;
                }
                stone.Update(gameTime, Game.Window.ClientBounds);
            }
        }