/// <summary> /// tank's A.I. function. /// moves to the position and stops when collides with others. /// </summary> /// <param name="aiBase">current A.I.</param> /// <param name="gameTime"></param> public override void OnAIMoveEvent(AIBase aiBase, GameTime gameTime) { if (aiBase.IsActive) { Vector3 vMoveVelocity = new Vector3(0.0f, 0.0f, SpecData.MoveSpeed); CollisionResult result = MoveHitTest(gameTime, vMoveVelocity); if (result != null) { if (GameSound.IsPlaying(soundMove)) { GameSound.Stop(soundMove); } MoveStop(); // Cannot move } else { Move(vMoveVelocity); if (!GameSound.IsPlaying(soundMove)) { soundMove = GameSound.Play3D(SoundTrack.TankMove, this); } } } else { if (GameSound.IsPlaying(soundMove)) { GameSound.Stop(soundMove); } MoveStop(); turretAngleSpeed = 0.0f; SetNextAI(AIType.Search, HelperMath.RandomNormal()); } }
/// <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> /// reloads weapon. /// plays reloading particle depending on unit type. /// </summary> /// <param name="type">unit type</param> /// <returns></returns> public bool Reload(UnitTypeId type) { this.state = WeaponState.Reloading; ParticleType reloadParticle = ParticleType.Count; SoundTrack reloadSound = SoundTrack.Count; switch (this.WeaponType) { case WeaponType.PlayerMachineGun: { reloadParticle = ParticleType.PlayerMachineGunReload; switch (type) { case UnitTypeId.Grund: case UnitTypeId.Kiev: reloadSound = SoundTrack.PlayerMachineGunGrundReload; break; case UnitTypeId.Mark: case UnitTypeId.Yager: reloadSound = SoundTrack.PlayerMachineGunMarkReload; break; } } break; case WeaponType.PlayerShotgun: { // Shotgun reload is no particle reloadSound = SoundTrack.PlayerShotgunReload; } break; case WeaponType.PlayerHandgun: { reloadParticle = ParticleType.PlayerHandgunReload; reloadSound = SoundTrack.PlayerHandgunReload; } break; } // Play a reloading particle if (reloadParticle != ParticleType.Count) { for (int i = 0; i < SpecData.ModelCount; i++) { int boneIdx = -1; Matrix boneTransform = Matrix.Identity; boneIdx = this.indexWeaponFireDummy[i]; boneTransform = modelWeapon[i].BoneTransforms[boneIdx]; if (reloadParticle != ParticleType.Count) { GameParticle.PlayParticle(reloadParticle, boneTransform, Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } } } switch (this.WeaponType) { case WeaponType.PlayerMachineGun: { if (GameSound.IsPlaying(soundFire)) { GameSound.Stop(soundFire); } } break; } // Play a reload sound if (reloadSound != SoundTrack.Count) { if (RobotGameGame.CurrentGameLevel.Info.GamePlayType == GamePlayTypeId.Versus) { soundReload = GameSound.Play3D(reloadSound, RobotGameGame.SinglePlayer.Emitter); } else { soundReload = GameSound.Play3D(reloadSound, this.OwnerUnit.Emitter); } } return(true); }
/// <summary> /// checks for the collision at the aiming angle. /// If it collides with an enemy mech, calls ActionHit() function. /// Weapon’s collision checks the world and enemy both. /// When playing firing particle, the number of the weapon’s model /// must be considered. /// Since the player’s weapon is a dual weapon system, there are two models. /// However, for enemies, there are enemies with single weapon system. /// Therefore, it plays firing particle at the gun point /// as many as the number of models. /// </summary> /// <param name="position">the start position of firing</param> /// <param name="direction">the direction of firing</param> /// <param name="distance">the range of firing</param> /// <param name="targetCollisionLayer">target collision layer</param> /// <param name="worldCollisionLayer">world collision layer</param> /// <param name="fireBone1">the fire matrix of first weapon</param> /// <param name="fireBone2">the fire matrix of second weapon</param> /// <returns></returns> public bool Fire(Vector3 position, Vector3 direction, float distance, ref CollisionLayer targetCollisionLayer, ref CollisionLayer worldCollisionLayer, Matrix?fireBone1, Matrix?fireBone2) { bool hit = false; Vector3 firePosition = Vector3.Zero; Vector3 targetPosition = position + (direction * distance); SoundTrack fireSound = SoundTrack.Count; ParticleType fireParticle = ParticleType.Count; ParticleType unitHitParticle = ParticleType.Count; ParticleType worldHitParticle = ParticleType.Count; Matrix fixedAxis = Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)); this.state = WeaponState.Firing; if (this.currentAmmo <= 0) { return(hit); } // Reduces a bullet. this.currentAmmo--; switch (this.WeaponType) { case WeaponType.PlayerMachineGun: { fireSound = SoundTrack.PlayerMachineGunFire; fireParticle = ParticleType.PlayerMachineGunFire; unitHitParticle = ParticleType.PlayerMachineGunUnitHit; worldHitParticle = ParticleType.PlayerMachineGunWorldHit; } break; case WeaponType.PlayerShotgun: { fireSound = SoundTrack.PlayerShotgunFire; fireParticle = ParticleType.PlayerShotgunFire; unitHitParticle = ParticleType.PlayerShotgunUnitHit; worldHitParticle = ParticleType.PlayerShotgunWorldHit; } break; case WeaponType.PlayerHandgun: { fireSound = SoundTrack.PlayerHandgunFire; fireParticle = ParticleType.PlayerHandgunFire; unitHitParticle = ParticleType.PlayerHandgunUnitHit; worldHitParticle = ParticleType.PlayerHandgunWorldHit; } break; case WeaponType.CameleerGun: { fireSound = SoundTrack.CameleerFire; fireParticle = ParticleType.EnemyGunFire; unitHitParticle = ParticleType.EnemyGunUnitHit; worldHitParticle = ParticleType.EnemyGunWorldHit; } break; case WeaponType.MaomingGun: { fireSound = SoundTrack.MaomingFire; fireParticle = ParticleType.PlayerMachineGunFire; unitHitParticle = ParticleType.EnemyGunUnitHit; worldHitParticle = ParticleType.EnemyGunWorldHit; } break; case WeaponType.DuskmasCannon: { fireSound = SoundTrack.DuskmasFire; fireParticle = ParticleType.EnemyCannonFire; unitHitParticle = ParticleType.EnemyCannonUnitHit; worldHitParticle = ParticleType.EnemyCannonWorldHit; } break; case WeaponType.TigerCannon: { fireSound = SoundTrack.TankFire; fireParticle = ParticleType.EnemyCannonFire; unitHitParticle = ParticleType.EnemyCannonUnitHit; worldHitParticle = ParticleType.EnemyCannonWorldHit; } break; case WeaponType.HammerCannon: { fireSound = SoundTrack.HammerFire; fireParticle = ParticleType.EnemyCannonFire; unitHitParticle = ParticleType.EnemyCannonUnitHit; worldHitParticle = ParticleType.EnemyCannonWorldHit; } break; case WeaponType.PhantomMelee: { fireSound = SoundTrack.BossMelee; fireParticle = ParticleType.Count; unitHitParticle = ParticleType.EnemyMeleeUnitHit; worldHitParticle = ParticleType.EnemyCannonWorldHit; } break; } if (this.WeaponType != WeaponType.PlayerShotgun && this.WeaponType != WeaponType.PlayerHandgun) { StopFireSound(); } // Play a weapon firing sound if (RobotGameGame.CurrentGameLevel.Info.GamePlayType == GamePlayTypeId.Versus) { soundFire = GameSound.Play3D(fireSound, RobotGameGame.SinglePlayer.Emitter); } else { soundFire = GameSound.Play3D(fireSound, this.OwnerUnit.Emitter); } // Play firing particles if (specData.ModelAlone) { // Multi fire if (this.SpecData.FireCount == 1) { for (int i = 0; i < SpecData.ModelCount; i++) { int boneIdx = indexWeaponFireDummy[i]; Matrix boneTransform = modelWeapon[i].BoneTransforms[boneIdx]; GameParticle.PlayParticle(fireParticle, boneTransform, fixedAxis); } // In case of two handed weapons, the index is changed // so that the tracer bullet will fire alternatively. if (dummySwichingIndex == 0) { dummySwichingIndex = 1; } else { dummySwichingIndex = 0; } int boneIndex = indexWeaponFireDummy[dummySwichingIndex]; firePosition = modelWeapon[dummySwichingIndex].BoneTransforms[ boneIndex].Translation; } // Delayed fire else { if (this.fireCount == 0) { GameParticle.PlayParticle(fireParticle, this.RightFireBone, fixedAxis); firePosition = this.RightFireBone.Translation; } else if (this.fireCount == 1) { GameParticle.PlayParticle(fireParticle, this.LeftFireBone, fixedAxis); firePosition = this.LeftFireBone.Translation; } } } else { Matrix fireMatrix = Matrix.Identity; if (fireBone1 != null) { GameParticle.PlayParticle(fireParticle, (Matrix)fireBone1, fixedAxis); } if (fireBone2 != null) { GameParticle.PlayParticle(fireParticle, (Matrix)fireBone2, fixedAxis); } if (fireBone1 != null && fireBone2 != null) { // In case of two handed weapons, the index is changed // so that the tracer bullet will fire alternatively. if (dummySwichingIndex == 0) { fireMatrix = (Matrix)fireBone1; dummySwichingIndex = 1; } else { fireMatrix = (Matrix)fireBone2; dummySwichingIndex = 0; } } else if (fireBone1 != null) { fireMatrix = (Matrix)fireBone1; } else if (fireBone2 != null) { fireMatrix = (Matrix)fireBone2; } firePosition = fireMatrix.Translation; } // Hit testing CollisionResult collideResult = FireHitTest(position, direction, distance, ref targetCollisionLayer, ref worldCollisionLayer); if (collideResult != null) { // Play hitting particle { ParticleType hitParticle = ParticleType.Count; // To player if (collideResult.detectedCollide.Owner is GameUnit) { GameUnit detectGameUnit = collideResult.detectedCollide.Owner as GameUnit; // Calculate a random intersect point for // hitting particle in unit sphere CollideSphere sphere = collideResult.detectedCollide as CollideSphere; switch (this.WeaponType) { case WeaponType.PlayerMachineGun: case WeaponType.PlayerShotgun: case WeaponType.PlayerHandgun: case WeaponType.CameleerGun: case WeaponType.MaomingGun: { Vector3 dir = this.OwnerUnit.Position - detectGameUnit.Position; dir.Normalize(); dir.X += HelperMath.RandomNormal2(); dir.Y += HelperMath.RandomNormal2(); dir.Normalize(); collideResult.normal = (Vector3)dir; collideResult.intersect = sphere.BoundingSphere.Center + ((Vector3)dir * sphere.Radius); } break; case WeaponType.DuskmasCannon: case WeaponType.HammerCannon: case WeaponType.TigerCannon: case WeaponType.PhantomMelee: { Vector3 dir = this.OwnerUnit.Position - sphere.BoundingSphere.Center; dir.Normalize(); collideResult.normal = (Vector3)dir; collideResult.intersect = sphere.BoundingSphere.Center; } break; } hitParticle = unitHitParticle; targetPosition = (Vector3)collideResult.intersect; } // To world else { hitParticle = worldHitParticle; targetPosition = (Vector3)collideResult.intersect; } if (collideResult.normal != null) { GameParticle.PlayParticle(hitParticle, (Vector3)collideResult.intersect, (Vector3)collideResult.normal, Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } else { GameParticle.PlayParticle(hitParticle, Matrix.CreateTranslation((Vector3)collideResult.intersect), Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } } // Hit to other mech if (collideResult.detectedCollide.Owner is GameUnit) { GameUnit HitUnit = (GameUnit)collideResult.detectedCollide.Owner; // Call hit function to unit HitUnit.ActionHit(this.OwnerUnit); if (HitUnit.IsDead) { if (this.OwnerUnit is GamePlayer) { // If the versus mode, you'll be get kill point if (RobotGameGame.CurrentStage is VersusStageScreen) { VersusStageScreen stage = RobotGameGame.CurrentStage as VersusStageScreen; GamePlayer player = this.OwnerUnit as GamePlayer; player.KillPoint++; stage.DisplayKillPoint((int)player.PlayerIndex, player.KillPoint); } } } hit = true; } } // Fire the tracer bullet particle if (this.specData.TracerBulletFire) { RobotGameGame.CurrentStage.TracerBulletManager.Fire(0, firePosition, targetPosition, this.specData.TracerBulletSpeed, this.specData.TracerBulletLength, this.specData.TracerBulletThickness, true); } // Cannot fire return(hit); }
/// <summary> /// processes the current action info. /// </summary> /// <param name="gameTime"></param> protected void ProcessAction(GameTime gameTime) { switch (CurrentAction) { // Playing damage animation process case Action.Damage: { // Return to idle state ActionIdle(); this.actionElapsedTime = 0.0f; } break; case Action.Fire: { if (this.actionElapsedTime >= CurrentWeapon.SpecData.FireIntervalTime) { // Return to idle state ActionIdle(); this.actionElapsedTime = 0.0f; } else { this.actionElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } } break; case Action.Reload: { if (this.actionElapsedTime >= CurrentWeapon.SpecData.ReloadIntervalTime) { // Return to idle state ActionIdle(); this.actionElapsedTime = 0.0f; } else { this.actionElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } } break; // Playing dead animation process case Action.Dead: { const float duration = 1.0f; const float secondDestroyGap = 1.0f; if (this.actionElapsedTime < duration + secondDestroyGap) { if (this.actionElapsedTime >= secondDestroyGap) { Material.alpha = ((duration + secondDestroyGap) - this.actionElapsedTime) / secondDestroyGap; // Second destroy particle if (GameSound.IsPlaying(soundDestroy2) == false) { soundDestroy2 = GameSound.Play3D( SoundTrack.DestroyHeavyMech2, this); Matrix world = Matrix.CreateTranslation( WorldTransform.Translation); GameParticle.PlayParticle(ParticleType.DestroyTank2, world, Matrix.Identity); } } } if (this.actionElapsedTime >= duration + secondDestroyGap) { this.Enabled = false; this.Visible = false; } else { this.actionElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } } break; } }
/// <summary> /// finalizes this screen. /// </summary> public override void FinalizeScreen() { GameSound.StopAll(); FrameworkCore.ScreenManager.FadeBackBufferToBlack(255); }
/// <summary> /// decides the moving animation according to velocity. /// </summary> /// <param name="gameTime"></param> /// <param name="vMoveVelocity"></param> public void ActionMovement(GameTime gameTime, Vector3 vMoveVelocity) { bool canMove = true; // Forward if (vMoveVelocity.Z > 0.0f) { if (CurrentAction != Action.ForwardWalk) { engageAction = Action.ForwardWalk; } } // Backward else if (vMoveVelocity.Z < 0.0f) { if (CurrentAction != Action.BackwardWalk) { engageAction = Action.BackwardWalk; } } else if (vMoveVelocity.X > 0.0f) { if (CurrentAction != Action.RightWalk) { engageAction = Action.RightWalk; } } // Backward else if (vMoveVelocity.X < 0.0f) { if (CurrentAction != Action.LeftWalk) { engageAction = Action.LeftWalk; } } // Move Stop else { canMove = false; ActionIdle(); } if (canMove) { // Play a moving sound if (engageAction == Action.ForwardWalk || engageAction == Action.BackwardWalk || engageAction == Action.RightWalk || engageAction == Action.LeftWalk) { if ((CurrentAction != Action.ForwardWalk && CurrentAction != Action.BackwardWalk && CurrentAction != Action.RightWalk && CurrentAction != Action.LeftWalk) || moveElapsedTime == 0.0f) { GameSound.Stop(soundMove); soundMove = GameSound.Play3D(SoundTrack.BossWalk, this); moveElapsedTime = 0.0f; } // Calculate run animation playing time for run sound if (moveDurationTime > moveElapsedTime) { moveElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { moveElapsedTime = 0.0f; } } } else { if (GameSound.IsPlaying(soundMove)) { GameSound.Stop(soundMove); } } }
/// <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> /// takes a damaged action. /// </summary> /// <param name="attackerPosition">the position of attacker</param> public override void ActionDead(Vector3 attackerPosition) { ParticleType type = ParticleType.Count; Vector3 dir = Vector3.Normalize(attackerPosition - Position); float FrontDot = Vector3.Dot(Direction, dir); float RightDot = Vector3.Dot(Right, dir); if (FrontDot > 0.5f) { // Hit from front engageAction = Action.BackwardDead; } else if (FrontDot < -0.5f) { // Hit from back engageAction = Action.ForwardDead; } else if (RightDot >= 0.0f) { // Hit from right engageAction = Action.LeftDead; } else if (RightDot < 0.0f) { // Hit from left engageAction = Action.RightDead; } if (UnitClass == UnitClassId.LightMech) { soundDestroy1 = GameSound.Play3D(SoundTrack.DestroyLightMech1, this); type = ParticleType.DestroyLightMech1; } else if (UnitClass == UnitClassId.HeavyMech) { soundDestroy1 = GameSound.Play3D(SoundTrack.DestroyHeavyMech1, this); type = ParticleType.DestroyHeavyMech1; } Matrix world = Matrix.CreateTranslation(WorldTransform.Translation); GameParticle.PlayParticle(type, world, Matrix.Identity); // Remove collision colLayerEnemyMech.RemoveCollide(this.Collide); colLayerAllMech.RemoveCollide(this.Collide); MoveStop(); GameSound.Stop(soundMove); Material.alpha = 1.0f; Material.diffuseColor = Color.Black; Material.specularColor = Color.Black; Material.emissiveColor = Color.Black; Material.vertexColorEnabled = true; this.SourceBlend = Blend.SourceAlpha; this.DestinationBlend = Blend.InverseSourceAlpha; this.AlphaBlendEnable = true; this.ReferenceAlpha = 0; // AI process stop AIContext.Enabled = false; }
/// <summary> /// determines the animation according to velocity. /// </summary> /// <param name="gameTime"></param> /// <param name="vMoveVelocity"></param> public void ActionMovement(GameTime gameTime, Vector3 vMoveVelocity) { bool canMove = true; // Forward if (vMoveVelocity.Z > 0.0f) { if (CurrentAction != Action.ForwardWalk) { engageAction = Action.ForwardWalk; } } // Backward else if (vMoveVelocity.Z < 0.0f) { if (CurrentAction != Action.BackwardWalk) { engageAction = Action.BackwardWalk; } } else if (vMoveVelocity.X > 0.0f) { if (CurrentAction != Action.RightWalk) { engageAction = Action.RightWalk; } } // Backward else if (vMoveVelocity.X < 0.0f) { if (CurrentAction != Action.LeftWalk) { engageAction = Action.LeftWalk; } } // Move Stop else { canMove = false; ActionIdle(); } SoundTrack moveSound = SoundTrack.CameleerWalk; switch (this.UnitType) { case UnitTypeId.Cameleer: moveSound = SoundTrack.CameleerWalk; break; case UnitTypeId.Maoming: moveSound = SoundTrack.MaomingWalk; break; case UnitTypeId.Duskmas: moveSound = SoundTrack.DuskmasWalk; break; case UnitTypeId.Tiger: moveSound = SoundTrack.TankMove; break; case UnitTypeId.Hammer: moveSound = SoundTrack.HammerWalk; break; } if (canMove) { // Play a moving sound if (engageAction == Action.ForwardWalk || engageAction == Action.BackwardWalk || engageAction == Action.RightWalk || engageAction == Action.LeftWalk) { if ((CurrentAction != Action.ForwardWalk && CurrentAction != Action.BackwardWalk && CurrentAction != Action.RightWalk && CurrentAction != Action.LeftWalk) || moveElapsedTime == 0.0f) { GameSound.Stop(soundMove); soundMove = GameSound.Play3D(moveSound, this); moveElapsedTime = 0.0f; } // Calculate run animation playing time for run sound if (moveDurationTime > moveElapsedTime) { moveElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { moveElapsedTime = 0.0f; } } } else { if (GameSound.IsPlaying(soundMove)) { GameSound.Stop(soundMove); } } }
/// <summary> /// processes the current action info. /// </summary> /// <param name="gameTime"></param> protected void ProcessAction(GameTime gameTime) { switch (CurrentAction) { // Playing damage animation process case Action.Damage: { AnimationSequence animation = GetAnimation(indexAnimation[(int)CurrentAction]); if (this.actionElapsedTime >= animation.Duration) { // Return to idle state ActionIdle(); this.actionElapsedTime = 0.0f; } else { this.actionElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } } break; case Action.Fire: case Action.Melee: { if (this.actionElapsedTime >= CurrentWeapon.SpecData.FireIntervalTime) { // Return to idle state ActionIdle(); this.actionElapsedTime = 0.0f; } else { this.actionElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } } break; case Action.Reload: { if (this.actionElapsedTime >= CurrentWeapon.SpecData.ReloadIntervalTime) { // Return to idle state ActionIdle(); this.actionElapsedTime = 0.0f; } else { this.actionElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } } break; // Playing dead animation process case Action.ForwardDead: case Action.BackwardDead: case Action.LeftDead: case Action.RightDead: { AnimationSequence animation = GetAnimation(indexAnimation[(int)CurrentAction]); const float secondDestroyGap = 0.5f; if (this.actionElapsedTime < animation.Duration + secondDestroyGap) { if (this.actionElapsedTime >= animation.Duration - 0.5f) { ParticleType type = ParticleType.Count; SoundTrack sound = SoundTrack.DestroyLightMech2; Material.alpha = ((animation.Duration + secondDestroyGap) - this.actionElapsedTime) / secondDestroyGap; switch (this.UnitClass) { case UnitClassId.LightMech: { sound = SoundTrack.DestroyLightMech2; type = ParticleType.DestroyLightMech2; } break; case UnitClassId.HeavyMech: { sound = SoundTrack.DestroyHeavyMech2; type = ParticleType.DestroyHeavyMech2; } break; } ; // Second destroy particle if (GameSound.IsPlaying(soundDestroy2) == false) { soundDestroy2 = GameSound.Play3D(sound, this); Matrix world = Matrix.CreateTranslation( WorldTransform.Translation); GameParticle.PlayParticle(type, world, Matrix.Identity); } } } if (this.actionElapsedTime >= animation.Duration + secondDestroyGap) { this.Enabled = false; this.Visible = false; } else { this.actionElapsedTime += (float)gameTime.ElapsedGameTime.TotalSeconds; } } break; } }
/// <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; } } }