Exemplo n.º 1
0
        public void LoadGameLevel(string levelName)
        {
            Level            = levelMap[levelName];
            CurrentLevelName = levelName;

            foreach (var obj in GameObjects)
            {
                obj.Init();
            }

            GameHUD       = new HUD(this, Mario);
            LevelScroller = new LevelScroller(this, GameObjects, Level);

            controllers = new List <IController> {
                new KeyboardController(),
                new GamepadController()
            };

            GamePlayKeyBinds();
        }
Exemplo n.º 2
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            if (Level.IsOutside)
            {
                GraphicsDevice.Clear(Color.CornflowerBlue);
            }
            else
            {
                GraphicsDevice.Clear(new Color(new Vector3(150 / 255.0f, 175 / 255.0f, 175 / 255.0f)));
            }

            spriteBatch.Begin(blendState: BlendState.AlphaBlend);

            LevelScroller.Draw(spriteBatch);

            GameHUD.Draw(spriteBatch);

            spriteBatch.End();

            base.Draw(gameTime);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // update inputs
            foreach (var controller in controllers)
            {
                controller.UpdateInput();
            }

            if (!IsGameOver)
            {
                LevelScroller.layers[2].Enabled = true;
                LevelScroller.layers[3].Enabled = true;
                LevelScroller.layers[4].Enabled = false;
                LevelScroller.layers[5].Enabled = false;

                if (Paused)
                {
                    MediaPlayer.Pause();
                }
                else
                {
                    MediaPlayer.Resume();
                }

                GameHUD.Update(gameTime);

                // add to-spawn items to the gameobjects list
                GameObjects.AddRange(Level.ToSpawn);
                Level.ToSpawn.Clear();

                if (Mario.IsDead)
                {
                    if (Mario.TimeDied.TotalMilliseconds == 0)
                    {
                        Mario.TimeDied = gameTime.TotalGameTime;
                    }
                    else if (gameTime.TotalGameTime > Mario.TimeDied + new TimeSpan(0, 0, 0, 3))
                    {
                        if (HUDMap["Lives"] <= 0)
                        {
                            GameOver();
                        }
                        else
                        {
                            HUDMap["Lives"]--;
                            LoadGameLevel("mini_game");
                            MediaPlayer.Play(backGroundMusic);
                            Mario.Respawn();
                        }
                    }
                }

                if (Mario.ReachedGate)
                {
                    Mario.ReachedGate = false;
                    LoadGameLevel("hospital");
                    Mario.Respawn();
                }

                if (Mario.OnFlagpole)
                {
                    if (Mario.TimeWon.TotalMilliseconds == 0)
                    {
                        Mario.TimeWon = gameTime.TotalGameTime;
                    }
                    else if (gameTime.TotalGameTime > Mario.TimeWon + new TimeSpan(0, 0, 0, 5))
                    {
                        GameWon();
                    }
                }

                // update all game objects (their sprites are updated inside)
                foreach (var obj in GameObjects)
                {
                    if (!Paused)
                    {
                        obj.Update(gameTime);
                    }
                }

                UpdateCollisions();    // update collisions

                CleanDeletedObjects(); // remove any deleted items from anywhere they might remain
            }

            base.Update(gameTime);

            LevelScroller.Update();
        }