/// <summary> /// creates a player character. /// </summary> /// <param name="specFileName">player spec file(.spec)</param> /// <param name="sceneParent">3D scene parent node</param> protected void CreatePlayer(string specFileName, NodeBase sceneParent) { GamePlayerSpec spec = new GamePlayerSpec(); spec = (GamePlayerSpec)GameDataSpecManager.Load(specFileName, spec.GetType()); GamePlayer player = null; switch (GameLevel.PlayerCountInLevel) { case 0: { player = new GamePlayer(ref spec, PlayerIndex.One); RobotGameGame.SinglePlayer = player; FrameworkCore.GameEventManager.TargetScene = player; } break; case 1: { player = new GamePlayer(ref spec, PlayerIndex.Two); } break; default: throw new InvalidOperationException( "Added player count is overflow"); } // Entry enemies in 3D Scene root node sceneParent.AddChild(player); // Create rotation axis Matrix rot = Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)); player.SetRootAxis(rot); // Set material RenderMaterial material = new RenderMaterial(); material.alpha = 1.0f; material.diffuseColor = new Color(210, 210, 210); material.specularColor = new Color(60, 60, 60); material.emissiveColor = new Color(30, 30, 30); material.specularPower = 24; material.vertexColorEnabled = false; material.preferPerPixelLighting = false; player.Material = material; player.ActiveFog = true; player.ActiveLighting = true; // Create collision data Vector3 centerPos = Vector3.Transform( new Vector3(0.0f, spec.MechRadius, 0.0f), Matrix.Invert(rot)); CollideSphere collide = new CollideSphere(centerPos, spec.MechRadius); player.EnableCulling = true; player.SetCollide(collide); player.ActionIdle(); // Add collide RobotGameGame.CurrentGameLevel.CollisionVersusTeam[ GameLevel.PlayerCountInLevel].AddCollide(collide); RobotGameGame.CurrentGameLevel.CollisionLayerAllMech.AddCollide(collide); // Set the respawn position if (player.PlayerIndex == PlayerIndex.One) { int count = GameLevel.Info.RespawnInLevelList.Count; int rndIndex = HelperMath.Randomi(0, count); RespawnInLevel respawn = GameLevel.Info.RespawnInLevelList[rndIndex]; player.SpawnPoint = Matrix.CreateRotationY(MathHelper.ToRadians(respawn.SpawnAngle)) * Matrix.CreateTranslation(respawn.SpawnPoint); } else if (player.PlayerIndex == PlayerIndex.Two) { GamePlayer gamePlayerOne = GameLevel.GetPlayerInLevel(0); RespawnInLevel respawn = GameLevel.FindRespawnMostFar(gamePlayerOne.SpawnPoint.Translation); player.SpawnPoint = Matrix.CreateRotationY(MathHelper.ToRadians(respawn.SpawnAngle)) * Matrix.CreateTranslation(respawn.SpawnPoint); } GameLevel.AddPlayer(player); }
/// <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); } } } }