Exemplo n.º 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: use this.Content to load your game content here
            _form  = new MyForm("Forms/MainMenu.dat", Content);
            _stage = new Stage();


            _menuSong       = Content.Load <Song>(@"Audios/menu");
            _backgroundSong = Content.Load <Song>(@"Audios/background");
            _selectSound    = Content.Load <SoundEffect>(@"Audios/select");
            _jumpSound      = Content.Load <SoundEffect>(@"Audios/jump");
            _dieSound       = Content.Load <SoundEffect>(@"Audios/die");
            _coinSound      = Content.Load <SoundEffect>(@"Audios/coin");
            _cutSound       = Content.Load <SoundEffect>(@"Audios/cut");
            _fireBallSound  = Content.Load <SoundEffect>(@"Audios/fireball");
            _boltSound      = Content.Load <SoundEffect>(@"Audios/bolt");
            _growSound      = Content.Load <SoundEffect>(@"Audios/grow");
            _getSkillSound  = Content.Load <SoundEffect>(@"Audios/getskill");
            _stage.Init(Content, "Data/Stages/Stage01.dat", this);
        }
Exemplo n.º 2
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)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            switch (_gameState)
            {
            case GameState.MainMenu:
                if (!songPlayed)
                {
                    MediaPlayer.Play(_menuSong);
                    MediaPlayer.IsRepeating = true;
                    songPlayed = true;
                }
                if (!loadMenuDone)
                {
                    if (_form.Buttons[0].TopLeft.X > 100)
                    {
                        Vector2 temp = _form.Buttons[0].TopLeft;
                        temp.X -= 15;
                        _form.Buttons[0].TopLeft = temp;
                    }
                    else
                    {
                        _form.Buttons[0].Color = Color.Wheat;
                        if (_form.Buttons[1].TopLeft.X > 100)
                        {
                            Vector2 temp = _form.Buttons[1].TopLeft;
                            temp.X -= 15;
                            _form.Buttons[1].TopLeft = temp;
                        }
                        else
                        {
                            _form.Buttons[1].Color = Color.Wheat;
                            if (_form.Buttons[2].TopLeft.X > 100)
                            {
                                Vector2 temp = _form.Buttons[2].TopLeft;
                                temp.X -= 15;
                                _form.Buttons[2].TopLeft = temp;
                            }
                            else
                            {
                                _form.Buttons[2].Color = Color.Wheat;
                                if (_form.Buttons[3].TopLeft.X > 100)
                                {
                                    Vector2 temp = _form.Buttons[3].TopLeft;
                                    temp.X -= 15;
                                    _form.Buttons[3].TopLeft = temp;
                                }
                                else
                                {
                                    _form.Buttons[3].Color = Color.Wheat;
                                    if (_form.Buttons[4].TopLeft.X > 100)
                                    {
                                        Vector2 temp = _form.Buttons[4].TopLeft;
                                        temp.X -= 15;
                                        _form.Buttons[4].TopLeft = temp;
                                    }
                                    else
                                    {
                                        _form.Buttons[4].Color = Color.Wheat;
                                        loadMenuDone           = true;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    iDelay++;            // Tang delay de tranh truong hop su kien press key qua nhanh
                    if (iDelay % 8 == 0) // 8 la dep roi. Them nua thi su kien press hoi cham.
                    {
                        iDelay   = 0;
                        _kbState = Keyboard.GetState();
                        if (_kbState.IsKeyDown(Keys.Up))
                        {
                            if (_selectedButton > 0)
                            {
                                _selectedButton--;
                                _selectSound.Play();
                            }
                        }
                        else
                        {
                            if (_kbState.IsKeyDown(Keys.Down))
                            {
                                if (_selectedButton < 4)
                                {
                                    _selectSound.Play();
                                    _selectedButton++;
                                }
                            }
                        }

                        _form.Buttons[_selectedButton].Color = Color.Tomato;
                        for (int i = 0; i < _form.Buttons.Count; i++)
                        {
                            if (i != _selectedButton)
                            {
                                _form.Buttons[i].Color = Color.Wheat;
                            }
                        }

                        // Bat su kien enter button
                        if (_kbState.IsKeyDown(Keys.Enter))
                        {
                            if (_form.IName == 11)
                            {
                                if (_selectedButton == 4)     // Exit game
                                {
                                    this.Exit();
                                }
                                else if (_selectedButton == 2)     // Setting menu
                                {
                                    //this.Exit();
                                }
                                else if (_selectedButton == 0)     // New Game
                                {
                                    _gameState = GameState.NewGame;
                                    songPlayed = false;
                                    MediaPlayer.Stop();
                                }
                                else if (_selectedButton == 3)     // User Manual
                                {
                                    _form = new MyForm("Forms/UserManual.dat", Content);
                                }
                            }
                            else
                            {
                                if (_form.IName == 10)
                                {
                                    if (_selectedButton == 0)
                                    {
                                        _form        = new MyForm("Forms/MainMenu.dat", Content);
                                        loadMenuDone = false;
                                    }
                                }
                            }
                            _selectedButton = 0;
                        }
                    }
                }
                _form.Update(gameTime);
                break;

            case GameState.NewGame:
                if (!songPlayed)
                {
                    MediaPlayer.Play(_backgroundSong);
                    MediaPlayer.IsRepeating = true;
                    songPlayed = true;
                }
                if (!_stage.isPlaying)
                {
                    _stage.Init(Content, "Data/Stages/Stage01.dat", this);
                }
                else
                {
                    _stage.Update(gameTime);
                }

                break;

            case GameState.Exit:
                this.Exit();
                break;
            }

            //base.Update(gameTime);
        }