/// <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); // Add spined background Texture2D bgTex = this.Content.Load <Texture2D>("images/Back"); bg = new BackgroundScene(this, spriteBatch, bgTex, Vector2.Zero); this.Components.Add(bg); //BGM intro = this.Content.Load <Song>("Sounds/intro"); MediaPlayer.IsRepeating = true; //Game Background song gameBGM = this.Content.Load <Song>("Sounds/game"); //instantiate StartScene startScene = new StartScene(this, spriteBatch); this.Components.Add(startScene); startScene.show(); //instantiate ActionScene actionScene = new ActionScene(this, spriteBatch); this.Components.Add(actionScene); //instantiate HelpScene helpScene = new HelpScene(this, spriteBatch); this.Components.Add(helpScene); //instantiate CreditScene creditScene = new CreditScene(this, spriteBatch); Components.Add(creditScene); //enable only one startscene startScene.show(); MediaPlayer.Play(intro); // ReturnToMenu(); }
/// <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) { //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) // Exit(); KeyboardState ks = Keyboard.GetState(); int selectedIndex = startScene.Menu.SelectedIndex; // if screen is menu if (startScene.Enabled) { if (ks.IsKeyDown(Keys.Enter)) { if (selectedIndex == (int)Menu.STARTGAME) { startScene.hide(); MediaPlayer.Stop(); LoadContent(); MediaPlayer.Play(gameBGM); HideAllScenes(); actionScene.show(); } else if (selectedIndex == (int)Menu.CREDIT) { startScene.hide(); creditScene.show(); } else if (selectedIndex == (int)Menu.HELP) { startScene.hide(); helpScene.show(); } else if (selectedIndex == (int)Menu.EXIT) { Exit(); } } } else if (helpScene.Enabled) { if (ks.IsKeyDown(Keys.Escape)) { startScene.show(); helpScene.hide(); } } else if (creditScene.Enabled) { if (ks.IsKeyDown(Keys.Escape)) { startScene.show(); creditScene.hide(); } } // if screen is not a menu else //if (actionScene.Enabled) { if (ks.IsKeyDown(Keys.Escape)) { Shared.currentLevel = 1; Shared.isPlaySameLevel = 1; MediaPlayer.Stop(); HideAllScenes(); startScene.show(); MediaPlayer.Play(intro); } if (ks.IsKeyDown(Keys.Space)) { if (Shared.currentLevel > Shared.TOTAL_LEVEL) { Shared.currentLevel = 1; Shared.isPlaySameLevel = 1; actionScene.hide(); } else { actionScene.hide(); if (Shared.isNextLevel) { Shared.isPlaySameLevel = 1; Shared.isNextLevel = false; } else { // Meaning that game is failed. if (Shared.isPlaySameLevel > Shared.TOTAL_PLAY) { Shared.currentLevel = 1; Shared.isPlaySameLevel = 1; } } } actionScene = new ActionScene(this, spriteBatch); this.Components.Add(actionScene); actionScene.show(); MediaPlayer.Play(gameBGM); } } // TODO: Add your update logic here base.Update(gameTime); }