/// <summary> /// initializes this screen. /// play a BGM sound. /// </summary> public override void InitializeScreen() { this.activeElapsedTime = TimeSpan.Zero; // creates a 2D layer. FrameworkCore.RenderContext.CreateScene2DLayer(1); this.refScene2DRoot = FrameworkCore.Scene2DLayers[0]; this.refScene2DRoot.AddChild(this.spriteMain); spriteObjMain = this.spriteMain.AddSprite(0, "MainTitle"); this.refScene2DRoot.AddChild(this.spriteButton); // Initialize start button spriteObjStartButton = this.spriteButton.AddSprite(0, "Start Button"); AddMenuEntry(spriteObjStartButton); // Entry a start button // Initialize versus button spriteObjVersusButton = this.spriteButton.AddSprite(1, "Versus Button"); AddMenuEntry(spriteObjVersusButton);// Entry a versus button // Initialize exit button spriteObjExitButton = this.spriteButton.AddSprite(2, "Exit Button"); AddMenuEntry(spriteObjExitButton); // Entry a exit button // calculates all image size. OnSize(); // play the title music. GameSound.Play(SoundTrack.MainTitle); // play an open menu sound. GameSound.Play(SoundTrack.MenuOpen); }
/// <summary> /// initializes this screen. /// </summary> public override void InitializeScreen() { base.InitializeScreen(); FrameworkCore.Viewer.ClearColor = Color.Black; NextScreen = new VersusReadyScreen(); TransitionOffTime = TimeSpan.FromSeconds(8.0f); FrameworkCore.RenderContext.ClearColor = Color.Black; // initializes for world everything. InitWorld(); // initializes for camera for this stage. InitCamera(); // Load Hud CreateHud(); for (int i = 0; i < GameLevel.PlayerCountInLevel; i++) { GamePlayer gamePlayer = GameLevel.GetPlayerInLevel(i); // Update selected weapon image in the Hud SetCurrentWeaponHud(i, gamePlayer.CurrentWeapon.WeaponType); } // Play a background music soundBGM = GameSound.Play(SoundTrack.FirstStage); }
/// <summary> /// initializes this screen. /// </summary> public override void InitializeScreen() { this.activeElapsedTime = TimeSpan.Zero; // Create a 2D layer FrameworkCore.RenderContext.CreateScene2DLayer(1); this.refScene2DRoot = FrameworkCore.Scene2DLayers[0]; // Play a title music GameSound.Play(SoundTrack.ReadyRoom); SetHorizontalEntryIndex(0, 0); SetHorizontalEntryIndex(1, 1); focusIndex[0] = 0; // default set focusIndex[1] = 1; // default set this.refScene2DRoot.AddChild(this.spriteBG); spriteObjBG = this.spriteBG.AddSprite(0, "Versus bg image"); this.refScene2DRoot.AddChild(this.spriteSelect); spriteObjSelectMech = new Sprite2DObject[4]; // Create the Grund image spriteObjSelectMech[0] = this.spriteSelect.AddSprite(0, "Grund"); // Create the Mark image spriteObjSelectMech[1] = this.spriteSelect.AddSprite(1, "Mark"); // Create the Kiev image spriteObjSelectMech[2] = this.spriteSelect.AddSprite(2, "Kiev"); // Create the Yager image spriteObjSelectMech[3] = this.spriteSelect.AddSprite(3, "Yager"); // Entry select player image AddMenuEntry(spriteObjSelectMech[0]); AddMenuEntry(spriteObjSelectMech[1]); AddMenuEntry(spriteObjSelectMech[2]); AddMenuEntry(spriteObjSelectMech[3]); this.refScene2DRoot.AddChild(this.spriteTextImage); // Create the VS image spriteObjVersus = this.spriteTextImage.AddSprite(0, "VS text"); // 1P image spriteObjSelectCursor[0] = this.spriteTextImage.AddSprite(1, "1P"); // 2P image spriteObjSelectCursor[1] = this.spriteTextImage.AddSprite(2, "2P"); // Calculate all image size OnSize(); // Play a open menu sound GameSound.Play(SoundTrack.MenuOpen); }
/// <summary> /// returns to main menu. /// </summary> void ReturnToTitleAccepted(object sender, EventArgs e) { // Accepeted to message box menu NextScreen = new MainMenuScreen(); TransitionOffTime = TimeSpan.FromSeconds(1.0f); ExitScreen(); // Play the select sound GameSound.Play(SoundTrack.MenuClose); }
/// <summary> /// calling when exit key pressed. /// </summary> public override void OnExit(int inputIndex) { MessageBoxScreen messageBox = new MessageBoxScreen("Are you sure you want to exit?"); // Register message box handle method messageBox.Accepted += ReturnToTitleAccepted; GameScreenManager.AddScreen(messageBox, true); // Play the open menu sound GameSound.Play(SoundTrack.MenuClose); }
/// <summary> /// calling when cancel key pressed. /// </summary> public override void OnCancel(int inputIndex) { // It prevents more than one input. if (inputIndex != 0) { return; } NextScreen = new MainMenuScreen(); TransitionOffTime = TimeSpan.FromSeconds(1.0f); ExitScreen(); // Play the select sound GameSound.Play(SoundTrack.MenuClose); }
/// <summary> /// Moves to selected menu. /// </summary> /// <param name="inputIndex">an index of the input</param> /// <param name="verticalEntryIndex"> /// a vertical index of selected entry /// </param> /// <param name="horizontalEntryIndex"> /// a horizontal index of selected entry /// </param> public override void OnSelectedEntry(int inputIndex, int verticalEntryIndex, int horizontalEntryIndex) { // It prevents more than one input. if (inputIndex != 0) { return; } if (ScreenState == ScreenState.Active) { // If selected a start button, jump to the first stage screen if (verticalEntryIndex == 0) { NextScreen = new LoadingScreen(); NextScreen.NextScreen = new FirstStageScreen(); TransitionOffTime = TimeSpan.FromSeconds(1.0f); ExitScreen(); } // If selected a versus button, jump to the versus ready screen else if (verticalEntryIndex == 1) { NextScreen = new VersusReadyScreen(); TransitionOffTime = TimeSpan.FromSeconds(1.0f); ExitScreen(); } // If selected a exit button, exit the program else if (verticalEntryIndex == 2) { // Allows the default game to exit on Xbox 360 and Windows MessageBoxScreen messageBox = new MessageBoxScreen("Are you sure you want to exit?"); // Register message box handle method messageBox.Accepted += RobotGameGame.ExitAccepted; GameScreenManager.AddScreen(messageBox, true); } // Play the select sound GameSound.Play(SoundTrack.MenuClose); } }
/// <summary> /// is called when the exit button is pressed. /// </summary> public override void OnExit(int inputIndex) { if (!this.IsActive) { return; } MessageBoxScreen messageBox = new MessageBoxScreen("Are you sure you want to exit?"); // Set to message box handle method messageBox.Accepted += RobotGameGame.ExitAccepted; GameScreenManager.AddScreen(messageBox, true); // Play the select sound GameSound.Play(SoundTrack.MenuClose); }
/// <summary> /// is called automatically when entry menu gets focused. /// </summary> /// <param name="inputIndex">an index of the input</param> /// <param name="verticalEntryIndex"> /// a vertical index of focused entry /// </param> /// <param name="horizontalEntryIndex"> /// a horizontal index of focused entry /// </param> public override void OnFocusEntry(int inputIndex, int verticalEntryIndex, int horizontalEntryIndex) { if (verticalEntryIndex >= MenuEntries.Count) { int value = MenuEntries.Count - 1; for (int i = 0; i < InputCount; i++) { SetVerticalEntryIndex(i, value); } verticalEntryIndex = value; } else if (verticalEntryIndex < 0) { for (int i = 0; i < InputCount; i++) { SetVerticalEntryIndex(i, 0); } verticalEntryIndex = 0; } // Play the focusing sound if (oldEntryIndex != verticalEntryIndex) { for (int i = 0; i < InputCount; i++) { SetVerticalEntryIndex(i, verticalEntryIndex); } GameSound.Play(SoundTrack.MenuFocus); oldEntryIndex = verticalEntryIndex; } }
/// <summary> /// checks the winning condition of the versus play. /// Any player who has destroyed the other as many as the kill point wins. /// </summary> protected override void CheckMission(GameTime gameTime) { if (isFinishedVersus == false) { for (int i = 0; i < GameLevel.PlayerCountInLevel; i++) { GamePlayer player = GameLevel.GetPlayerInLevel(i); // Whoever wins the set points first, the versus mode will end. if (RobotGameGame.VersusGameInfo.killPoint <= player.KillPoint) { isFinishedVersus = true; } } } if (isFinishedVersus) { // Visible mission result image if (missionResultElapsedTime > MissionResultVisibleTime) { this.spriteObjHudVersusWin.Visible = true; this.spriteObjHudVersusLose.Visible = true; } else { if (missionResultElapsedTime < MissionResultVisibleTime) { missionResultElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } this.spriteObjHudVersusWin.Visible = false; this.spriteObjHudVersusLose.Visible = false; } if (GameSound.IsPlaying(soundBGM)) { float scaleFactor = 1.0f; if (GameLevel.Info.GamePlayType == GamePlayTypeId.Versus) { scaleFactor = 0.8f; } // Scale the image size and position for screen resolution Vector2 sizeScale = new Vector2((float)FrameworkCore.ViewWidth * scaleFactor / (float)ViewerWidth.Width1080, (float)FrameworkCore.ViewHeight * scaleFactor / (float)ViewerHeight.Height1080); for (int i = 0; i < GameLevel.PlayerCountInLevel; i++) { GamePlayer player = GameLevel.GetPlayerInLevel(i); // Player sound and action stop player.MissionEnd(); // Win!! if (RobotGameGame.VersusGameInfo.killPoint <= player.KillPoint) { int scaledWidth = (int)((float)imageWinWidth * sizeScale.X); int scaledHeight = (int)((float)imageWinHeight * sizeScale.Y); int posX = (int)((FrameworkCore.ViewWidth / 2) - (scaledWidth / 2)); int posY = (int)((FrameworkCore.ViewHeight / 2) - (scaledHeight / 2)); if (player.PlayerIndex == PlayerIndex.One) { posY -= FrameworkCore.ViewHeight / 4; } else if (player.PlayerIndex == PlayerIndex.Two) { posY += FrameworkCore.ViewHeight / 4; } this.spriteObjHudVersusWin.ScreenRectangle = new Rectangle( posX, posY, scaledWidth, scaledHeight); } // Lose!! else { int scaledWidth = (int)((float)imageLoseWidth * sizeScale.X); int scaledHeight = (int)((float)imageLoseHeight * sizeScale.Y); int posX = (int)((FrameworkCore.ViewWidth / 2) - (scaledWidth / 2)); int posY = (int)((FrameworkCore.ViewHeight / 2) - (scaledHeight / 2)); if (player.PlayerIndex == PlayerIndex.One) { posY -= FrameworkCore.ViewHeight / 4; } else if (player.PlayerIndex == PlayerIndex.Two) { posY += FrameworkCore.ViewHeight / 4; } this.spriteObjHudVersusLose.ScreenRectangle = new Rectangle( posX, posY, scaledWidth, scaledHeight); } } // Stop background music GameSound.Stop(soundBGM); // Play success music GameSound.Play(SoundTrack.MissionClear); // Invisible all of the Hud SetVisibleHud(false); // Go to main menu NextScreen = new VersusReadyScreen(); TransitionOffTime = TimeSpan.FromSeconds(8.0f); ExitScreen(); } } else { // Respawns a destroyed player in the game. for (int i = 0; i < GameLevel.PlayerCountInLevel; i++) { GamePlayer player = GameLevel.GetPlayerInLevel(i); if (player.IsFinishedDead) { int otherSidePlayerIndex = -1; if (i == 0) { otherSidePlayerIndex = 1; } else if (i == 1) { otherSidePlayerIndex = 0; } GamePlayer otherSidePlayer = GameLevel.GetPlayerInLevel(otherSidePlayerIndex); // Find the farthest positions for enemy positions. RespawnInLevel respawn = GameLevel.FindRespawnMostFar( otherSidePlayer.WorldTransform.Translation); // Set to respawn position player.SpawnPoint = Matrix.CreateRotationY( MathHelper.ToRadians(respawn.SpawnAngle)) * Matrix.CreateTranslation(respawn.SpawnPoint); // Reset the player info player.Reset(true); } } } }
/// <summary> /// gets automatically called when the entry menu gets focused. /// </summary> /// <param name="inputIndex">an index of the input</param> /// <param name="verticalEntryIndex"> /// a vertical index of focused entry /// </param> /// <param name="horizontalEntryIndex"> /// a horizontal index of focused entry /// </param> public override void OnFocusEntry(int inputIndex, int verticalEntryIndex, int horizontalEntryIndex) { if (inputIndex != 0 && inputIndex != 1) { return; } // focused player mech { int focusAdd = 1; if (focusIndex[inputIndex] > horizontalEntryIndex) { focusAdd = -1; } int horizontalFocus = horizontalEntryIndex; // first, check out of range if (horizontalFocus >= MenuEntries.Count) { horizontalFocus = 0; SetHorizontalEntryIndex(inputIndex, horizontalFocus); } else if (horizontalFocus < 0) { horizontalFocus = MenuEntries.Count - 1; SetHorizontalEntryIndex(inputIndex, horizontalFocus); } // Cannot be focus same selection if (inputIndex == 0 && horizontalFocus == focusIndex[1]) { horizontalFocus = focusIndex[1] + focusAdd; SetHorizontalEntryIndex(inputIndex, horizontalFocus); } else if (inputIndex == 1 && horizontalFocus == focusIndex[0]) { horizontalFocus = focusIndex[0] + focusAdd; SetHorizontalEntryIndex(inputIndex, horizontalFocus); } // second, check out of range if (horizontalFocus >= MenuEntries.Count) { horizontalFocus = 0; SetHorizontalEntryIndex(inputIndex, horizontalFocus); } else if (horizontalFocus < 0) { horizontalFocus = MenuEntries.Count - 1; SetHorizontalEntryIndex(inputIndex, horizontalFocus); } focusIndex[inputIndex] = horizontalFocus; // Scaling image size and positioning for screen resolution Vector2 scale = new Vector2((float)FrameworkCore.ViewWidth / (float)ViewerWidth.Width1080, (float)FrameworkCore.ViewHeight / (float)ViewerHeight.Height1080); int selectIndex = this.focusIndex[inputIndex]; spriteObjSelectCursor[inputIndex].ScreenPosition = this.cursorScreenPosition[selectIndex] * scale; } // Play the focusing sound GameSound.Play(SoundTrack.MenuFocus); }
/// <summary> /// Moves to selected menu. /// </summary> /// <param name="inputIndex">an index of the input</param> /// <param name="verticalEntryIndex">vertical index of selected entry</param> /// <param name="horizontalEntryIndex">horizontal index of selected entry</param> public override void OnSelectedEntry(int inputIndex, int verticalEntryIndex, int horizontalEntryIndex) { // It prevents more than one input. if (inputIndex != 0) { return; } if (ScreenState == ScreenState.Active) { VersusGameInfo versusInfo = new VersusGameInfo(); versusInfo.playerSpec = new string[2]; for (int i = 0; i < 2; i++) { switch (focusIndex[i]) { case 0: // Grund { versusInfo.playerSpec[i] = "Data/Players/VersusGrund.spec"; } break; case 1: // Mark { versusInfo.playerSpec[i] = "Data/Players/VersusMark.spec"; } break; case 2: // Kiev { versusInfo.playerSpec[i] = "Data/Players/VersusKiev.spec"; } break; case 3: // Yager { versusInfo.playerSpec[i] = "Data/Players/VersusYager.spec"; } break; } } // Set to kill point versusInfo.killPoint = killPoint; // Set to versus information RobotGameGame.VersusGameInfo = versusInfo; // Play a select sound GameSound.Play(SoundTrack.MenuClose); // versus game start!! NextScreen = new LoadingScreen(); NextScreen.NextScreen = new VersusStageScreen(); TransitionOffTime = TimeSpan.FromSeconds(1.0f); ExitScreen(); } }
/// <summary> /// checks the mission objective during the game play. /// Moves to the next stage after the mission gets cleared, /// and when the mission is failed, returns to the main menu. /// </summary> /// <param name="gameTime"></param> protected override void CheckMission(GameTime gameTime) { // Checking mission if (IsMissionFailed == false) { IsMissionFailed = GameLevel.IsMissionFailed(); } if (IsMissionClear == false) { IsMissionClear = gameLevel.IsMissionClear(); } // Mission complete!! if (IsMissionClear ) { if (GameSound.IsPlaying(soundBGM)) { SetVisibleHud(false); // The volume for the sound effects besides the // background music will be lowered. FrameworkCore.SoundManager.SetVolume( SoundCategory.Default.ToString(), 0.4f); FrameworkCore.SoundManager.SetVolume( SoundCategory.Effect.ToString(), 0.4f); FrameworkCore.SoundManager.SetVolume( SoundCategory.Music.ToString(), 1.0f); // Stop background music GameSound.Stop(soundBGM); // Play victory music GameSound.Play(SoundTrack.MissionClear); // Player stop for (int i = 0; i < GameLevel.PlayerCountInLevel; i++) { GamePlayer player = GameLevel.GetPlayerInLevel(i); player.MissionEnd(); } if (NextScreen == null) throw new InvalidOperationException("Please set to next screen"); // Go to next stage ExitScreen(); } // display the clear image if (missionResultElapsedTime > MissionResultVisibleTime) { this.spriteObjMissionClear.Visible = true; } else { if (missionResultElapsedTime < MissionResultVisibleTime) { missionResultElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } this.spriteObjMissionClear.Visible = false; } } // Mission failed else if (IsMissionFailed ) { if (GameSound.IsPlaying(soundBGM)) { SetVisibleHud(false); // The volume for the sound effects besides the // background music will be lowered. FrameworkCore.SoundManager.SetVolume( SoundCategory.Default.ToString(), 0.4f); FrameworkCore.SoundManager.SetVolume( SoundCategory.Effect.ToString(), 0.4f); FrameworkCore.SoundManager.SetVolume( SoundCategory.Music.ToString(), 1.0f); // Stop background music GameSound.Stop(soundBGM); // Play fail music GameSound.Play(SoundTrack.MissionFail); // Player sound and action stop for (int i = 0; i < GameLevel.PlayerCountInLevel; i++) { GamePlayer player = GameLevel.GetPlayerInLevel(i); player.MissionEnd(); } // Go to main menu NextScreen = new MainMenuScreen(); TransitionOffTime = TimeSpan.FromSeconds(8.0f); ExitScreen(); } // display the failed image if (missionResultElapsedTime > MissionResultVisibleTime) { this.spriteObjMissionFailed.Visible = true; } else { if (missionResultElapsedTime < MissionResultVisibleTime) { missionResultElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } this.spriteObjMissionFailed.Visible = false; } } }