public void crearJuego(int width, int height) { size = new Vector2(width, height); this.pictureBox.Width = (int)size.X; this.pictureBox.Height = (int)size.Y; // test graphics.PreferredBackBufferWidth = pictureBox.Width; graphics.PreferredBackBufferHeight = pictureBox.Height; graphics.ApplyChanges(); escenaAccion = new ActionScene(this, fondo, size); escenaAccion.modoFramework = true; Components.Add(escenaAccion); escenaAccion.Show(); //escenaInicio.Show(); //escenaAyuda.Hide(); //escenaActiva = escenaInicio; escenaActiva = escenaAccion; }
/// <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) { // TODO: Add your update logic here int selectedIdx = 0; KeyboardState ks = Keyboard.GetState(); // manage menus & scenes if (startScene.Enabled) { if (oldState.IsKeyDown(Keys.Enter) && ks.IsKeyUp(Keys.Enter)) { selectedIdx = startScene.Menu.SelectedIdx; startScene.Hide(); if (selectedIdx == (int)MainMenu.Start) { actionScene.Show(); } else if (selectedIdx == (int)MainMenu.Help) { helpScene.Show(); } else if (selectedIdx == (int)MainMenu.HighScore) { RebootHighScoreScene(); highScoreScene.Show(); } else if (selectedIdx == (int)MainMenu.About) { aboutScene.Show(); } else if (selectedIdx == (int)MainMenu.Quit) { Exit(); } } } if (actionScene.Enabled) { if (actionScene.ShowGameOver) { actionScene.Enabled = false; gameOverScene.Score = (int)actionScene.Score; highScorePlayers = ReadScores(); // read scores // if there are players saved and the current score is lower compared to the highest one, // set highscore to this max one; // otherwise set to the current score if (highScorePlayers.Any() && gameOverScene.Score < highScorePlayers[0].Score) { gameOverScene.HighScore = highScorePlayers[0].Score; } else { gameOverScene.HighScore = (int)actionScene.Score; } gameOverScene.Show(); } } if (helpScene.Enabled) { if (ks.IsKeyDown(Keys.Escape)) { helpScene.Hide(); startScene.Show(); } } if (highScoreScene.Enabled) { if (ks.IsKeyDown(Keys.Escape)) { highScoreScene.Hide(); startScene.Show(); } } if (aboutScene.Enabled) { if (ks.IsKeyDown(Keys.Escape)) { aboutScene.Hide(); startScene.Show(); } } if (gameOverScene.Enabled && !gameOverScene.IsEditNameMode) { if (oldState.IsKeyDown(Keys.Enter) && ks.IsKeyUp(Keys.Enter)) { selectedIdx = gameOverScene.Menu.SelectedIdx; gameOverScene.Hide(); Player player = new Player(gameOverScene.Name, gameOverScene.Score); UpdateScores(player); // update the 'scores' file if (selectedIdx == (int)GameOverMenu.PlayAgain) { actionScene.Hide(); RebootActionScene(); actionScene.Show(); } else if (selectedIdx == (int)GameOverMenu.MainMenu) { gameOverScene.Menu.SelectedIdx = 0; actionScene.Hide(); //RebootGameOverScene(); RebootActionScene(); startScene.Show(); } } } oldState = ks; base.Update(gameTime); }
/// <summary> /// Controls the various scenes for the game, waiting for user input and responding with the correct follow up action /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { KeyboardState ks = Keyboard.GetState(); //the index of which menu item is currently hovered/selected int selectedIndex = 0; //check to see if were on menu screen if (menuScene.Enabled) { selectedIndex = menuScene.Menu.SelectedIndex; //sets the selected index if (selectedIndex == 0 && ks.IsKeyDown(Keys.Enter)) //if Play game is selected, hide the menu and menu music and play action scene with music { menuScene.Hide(); MediaPlayer.Stop(); actionScene.ResetGame(); actionScene.Show(); MediaPlayer.Play(actionSong); MediaPlayer.IsRepeating = true; MediaPlayer.Volume = 0.1f; } else if (selectedIndex == 1 && ks.IsKeyDown(Keys.Enter)) //if Help scene is selected, hide menu and show help scene { menuScene.Hide(); helpScene.Show(); } else if (selectedIndex == 2 && ks.IsKeyDown(Keys.Enter)) //if Credit scene is selected, hide menu and show credit scene { menuScene.Hide(); creditScene.Show(); } else if (selectedIndex == 3 && ks.IsKeyDown(Keys.Enter)) //if Quit is selected, close the application { Exit(); } } else if (actionScene.Enabled) //check to see if the user is on the action scene { if (ks.IsKeyDown(Keys.Escape)) { MediaPlayer.Stop(); actionScene.Hide(); menuScene.Show(); MediaPlayer.Play(menuSong); MediaPlayer.IsRepeating = true; } } else if (helpScene.Enabled) //check to see if user is on the help scene { if (ks.IsKeyDown(Keys.Escape)) { helpScene.Hide(); menuScene.Show(); } } else if (creditScene.Enabled) //check to see if the user is on the credit scene { if (ks.IsKeyDown(Keys.Escape)) { creditScene.Hide(); menuScene.Show(); } } else if (gameOverScene.Enabled) //check to see if the user is on the game over scene { if (ks.IsKeyDown(Keys.Escape)) { gameOverScene.Hide(); menuScene.Show(); MediaPlayer.Play(menuSong); MediaPlayer.IsRepeating = true; } } base.Update(gameTime); }