예제 #1
0
파일: Model.cs 프로젝트: Nazoon/Roboknight
        /// <summary>
        /// Constructor for the Model class
        /// </summary>
        /// <param name="content">A valid ContentManager</param>
        public Model(ContentManager content)
        {
            //Setting up content manager
            this.content = content;

            //Setting up Prev MS
            prevMS = Mouse.GetState();

            //Starts game, with a maximum floor size (length and width) of 100 rooms
            game = new GameField(content, 100);

            //Starts both states as neutral
            moveVector      = Vector2.Zero;
            weaponDirection = WeaponState.None;

            //The model begins with the game in focus
            modelState = ModelState.MainMenu;

            //Instantiates the menus
            mainMenu = new MainMenu();
            PlayerStats playerStats = game.GetPlayer().GetStats();

            pauseMenu    = new PauseMenu(this.content, game.GetCurrentRoom(), ref playerStats);
            gameOverMenu = new GameOverMenu();

            //Setting up music
            titleMusic    = this.content.Load <SoundEffect>(@"Sound\Music\title");
            dungeonMusic  = this.content.Load <SoundEffect>(@"Sound\Music\dungeon");
            gameOverMusic = this.content.Load <SoundEffect>(@"Sound\Music\gameover");

            //Setting up effects
            pauseEffect = this.content.Load <SoundEffect>(@"Sound\Menu\pause");

            //Setting up music instances
            titleInstance             = titleMusic.CreateInstance();
            dungeonInstance           = dungeonMusic.CreateInstance();
            gameOverInstance          = gameOverMusic.CreateInstance();
            titleInstance.IsLooped    = true;
            dungeonInstance.IsLooped  = true;
            gameOverInstance.IsLooped = false; //Game-over music sounds best when not looped
            titleInstance.Volume      = 0.3F;
            dungeonInstance.Volume    = 0.2F;
            gameOverInstance.Volume   = 0.3F;

            //Starts off with the main menu music
            titleInstance.Play();
        }
예제 #2
0
파일: Model.cs 프로젝트: Nazoon/Roboknight
        /// <summary>
        /// Updates the game
        /// </summary>
        /// <param name="gameTime">A valid GameTime</param>
        /// <param name="ms">A valid MouseState</param>
        public void Update(GameTime gameTime, MouseState ms)
        {
            switch (modelState)
            {
            case ModelState.Game:

                game.Update(gameTime, moveVector, weaponDirection);

                //Checks for Game-over condition
                if (game.GetPlayer().GetStats().GetHealth() <= 0)
                {
                    modelState = ModelState.GameOver;

                    //Plays game over music
                    dungeonInstance.Stop();
                    gameOverInstance.Play();
                }

                break;

            case ModelState.MainMenu:

                mainMenu.Update(ms);

                modelState = mainMenu.GetState();

                if (modelState == ModelState.Game)
                {
                    //Resets game
                    game = new GameField(content, 100);
                    PlayerStats playerStats = game.GetPlayer().GetStats();
                    pauseMenu    = new PauseMenu(this.content, game.GetCurrentRoom(), ref playerStats);
                    gameOverMenu = new GameOverMenu();

                    //Resets main menu state
                    mainMenu.SetState(ModelState.MainMenu);

                    //Plays game music
                    titleInstance.Stop();
                    dungeonInstance.Play();
                }

                break;

            case ModelState.PauseMenu:

                pauseMenu.Update(ms, game.GetCurrentRoom());

                break;

            case ModelState.GameOver:

                gameOverMenu.Update(ms);
                modelState = gameOverMenu.GetState();

                //Resets the game if the player selects
                if (modelState == ModelState.Game)
                {
                    //Resets game
                    game = new GameField(content, 100);

                    //Resets game over screen
                    gameOverMenu.SetState(ModelState.GameOver);

                    //Plays game music
                    gameOverInstance.Stop();
                    dungeonInstance.Play();
                }
                else if (modelState == ModelState.MainMenu)
                {
                    //Plays main menu music
                    gameOverInstance.Stop();
                    titleInstance.Play();
                }

                break;
            }

            //Cheat codes!
            if (Keyboard.GetState().IsKeyDown(Keys.LeftShift))
            {
                //LShift + X: Player gets 1,000,000 G
                if (Keyboard.GetState().IsKeyDown(Keys.X))
                {
                    game.GetPlayer().GetStats().SetGold(1000000);
                }

                //LShift + C: Player gets 1,000,000 HP
                if (Keyboard.GetState().IsKeyDown(Keys.C))
                {
                    game.GetPlayer().GetStats().SetHealth(1000000);
                }

                //LShift + Space: Clears all enemies in the current room
                //NOTE: Player does not recieve money for clearing room
                if (Keyboard.GetState().IsKeyDown(Keys.Space))
                {
                    game.GetCurrentRoom().GetEnemies().Clear();
                }

                //LShift + E: Clears all obstacles in the current room
                //NOTE: Will clear walls too, use at your own risk (you can walk into rooms that don't exist and crash the game)
                if (Keyboard.GetState().IsKeyDown(Keys.E))
                {
                    game.GetCurrentRoom().GetObstacles().Clear();
                }
            }
        }