/// <summary> /// creates a weapon for level. /// reads an weapon information file(.spec) and configures the weapon class. /// The read weapon class is stored in the list. /// </summary> /// <param name="info">weapon information for level</param> /// <param name="sceneParent">3D scene parent node</param> /// <returns>weapon class for the game</returns> protected GameWeapon CreateWeapon(WeaponInLevel info, NodeBase sceneParent) { GameWeaponSpec spec = new GameWeaponSpec(); spec = (GameWeaponSpec)GameDataSpecManager.Load(info.SpecFilePath, spec.GetType()); GameWeapon weapon = new GameWeapon(spec); // creates a collision data. Vector3 centerPos = Vector3.Transform(new Vector3(0f, spec.ModelRadius, 0f), Matrix.Invert(weapon.RootAxis)); CollideSphere collide = new CollideSphere(centerPos, spec.ModelRadius); weapon.SetCollide(collide); weapon.SetDroppedModelActiveFog(true); weapon.SetDroppedModelActiveLighting(false); // drop to world. weapon.Drop(info.Position, sceneParent, null); // adds a weapon to the list. weaponList.Add(weapon); return(weapon); }
/// <summary> /// creates an item for level. /// reads an item information file(.spec) and configures the item class. /// The read item class is stored in the list. /// </summary> /// <param name="info">item information for level</param> /// <param name="sceneParent">3D scene parent node</param> /// <returns>item class for the game</returns> protected GameItemBox CreateItemBox(ref ItemInLevel info, NodeBase sceneParent) { ItemBoxSpec spec = LoadItemSpec(ref info); GameItemBox item = new GameItemBox(spec); item.WorldTransform = Matrix.CreateTranslation(info.Position); item.SetRootAxis(Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); // creates a collision data. Vector3 centerPos = Vector3.Transform( new Vector3(0.0f, spec.ModelRadius, 0.0f), Matrix.Invert(item.RootAxis)); CollideSphere collide = new CollideSphere(centerPos, spec.ModelRadius); item.SetCollide(collide); item.EnableCulling = true; item.ActiveFog = true; item.ActiveLighting = false; // adds item to the list. itemList.Add(item); // adds item to parent scene node. sceneParent.AddChild(item); return(item); }
public CollisionResult MoveHitTestWithItem(Vector3 velocityAmount) { CollideSphere playerSphere = Collide as CollideSphere; float radius = playerSphere.Radius; // creates simulation sphere for collision. Matrix transformSimulate = TransformedMatrix * Matrix.CreateTranslation(velocityAmount); CollideSphere sphereSimulate = new CollideSphere(playerSphere.LocalCenter, radius); sphereSimulate.Transform(transformSimulate); sphereSimulate.Id = playerSphere.Id; // checks for the collision with items. CollisionResult result = FrameworkCore.CollisionContext.HitTest( sphereSimulate, ref colLayerItems, ResultType.NearestOne); if (result != null) { if (0.0f >= result.distance) { return(result); } } return(null); }
public CollisionResult MoveHitTestWithWorld(Vector3 velocityAmount) { CollideSphere playerSphere = Collide as CollideSphere; float radius = playerSphere.Radius; // calculate simulated position for collision. Matrix transformSimulate = TransformedMatrix * Matrix.CreateTranslation(velocityAmount); // first, check using sphere. { CollideSphere simulateSphere = new CollideSphere(playerSphere.LocalCenter, radius); simulateSphere.Transform(transformSimulate); simulateSphere.Id = playerSphere.Id; CollisionResult result = FrameworkCore.CollisionContext.HitTest( simulateSphere, ref colLayerMoveWorld, ResultType.NearestOne); if (result != null) { return(result); } } // second, check using ray. { Vector3 direction = velocityAmount; direction.Normalize(); CollideRay simulateRay = new CollideRay(playerSphere.BoundingSphere.Center, direction); simulateRay.Id = playerSphere.Id; CollisionResult result = FrameworkCore.CollisionContext.HitTest( simulateRay, ref colLayerMoveWorld, ResultType.NearestOne); if (result != null) { if (result.distance <= radius) { return(result); } } } return(null); }
/// <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> /// boss's A.I. function. /// turns the body left. /// </summary> /// <param name="aiBase">current A.I.</param> /// <param name="gameTime"></param> public override void OnAITurnLeftEvent(AIBase aiBase) { MoveStop(); if (aiBase.IsActive) { float fTurnAngleSpeed = SpecData.TurnAngle; // Turning left Rotate(new Vector2(fTurnAngleSpeed, 0.0f)); ActionTurn(fTurnAngleSpeed); } else { if (isMoveBlocked) { CollideSphere collideSphere = Collide as CollideSphere; float movingTime = (float)HelperMath.Randomi(2) + HelperMath.RandomNormal(); Vector3 simulateAmount = movingTime * new Vector3(0.0f, 0.0f, SpecData.MoveSpeed); simulateAmount = CalculateVelocity(simulateAmount); Vector3 start = WorldTransform.Translation + (WorldTransform.Up * 1.0f); // Test collision CollisionResult result = HitTestWithWorld(start, Direction); // Is moving way clear? if (result != null) { float moveDistance = (SpecData.MoveSpeed * movingTime); float resultDistance = result.distance - collideSphere.Radius; if (resultDistance > 0.0f) { if (resultDistance < moveDistance) { // Recalculate moving time for move and stop movingTime *= resultDistance / moveDistance; isMoveBlocked = true; } else { isMoveBlocked = false; } } // Can't move else { isMoveBlocked = true; } } else { isMoveBlocked = false; } if (isMoveBlocked) { // turn right SetNextAI(AIType.TurnRight, 90.0f / SpecData.TurnAngle); } else { SetNextAI(AIType.Move, movingTime); } } else { SetNextAI(AIType.Search, 0.2f); } } }
/// <summary> /// boss's A.I. function. /// checks whether there’s an enemy within shooting range. /// If there’s an enemy within the shooting range, it will fire, otherwise, /// it moves. /// </summary> /// <param name="aiBase">current A.I.</param> /// <param name="gameTime"></param> public override void OnAISearchEvent(AIBase aiBase) { if (!aiBase.IsActive) { CollideSphere collideSphere = Collide as CollideSphere; // Searching Player inside fire range float distanceBetweenPlayer = Vector3.Distance(RobotGameGame.SinglePlayer.Position, Position); Vector3 vTargetDirection = Vector3.Normalize(RobotGameGame.SinglePlayer.Position - Position); float dotRight = Vector3.Dot(Right, vTargetDirection); float dotDirection = Vector3.Dot(Direction, vTargetDirection); float angle = MathHelper.ToDegrees(dotRight); // Forward area if (dotDirection > 0.0f) { // Turning right if (angle > 5.0f) { SetNextAI(AIType.TurnRight, Math.Abs(angle) / SpecData.TurnAngle); } // Turning left else if (angle < -5.0f) { SetNextAI(AIType.TurnLeft, Math.Abs(angle) / SpecData.TurnAngle); } else { // Firing inside fire range if (distanceBetweenPlayer <= CurrentWeapon.SpecData.FireRange) { SetNextAI(AIType.Attack, 1.0f); } // Trace to player else { float movingTime = (float)HelperMath.Randomi(2) + HelperMath.RandomNormal(); Vector3 simulateAmount = movingTime * new Vector3(0.0f, 0.0f, SpecData.MoveSpeed); simulateAmount = CalculateVelocity(simulateAmount); Vector3 start = WorldTransform.Translation + (WorldTransform.Up * 1.0f); // Test collision CollisionResult result = HitTestWithWorld(start, Direction); // clear moving way ? if (result != null) { float moveDistance = (SpecData.MoveSpeed * movingTime); float resultDistance = result.distance - collideSphere.Radius; if (resultDistance > 0.0f) { if (resultDistance < moveDistance) { // Recalculate moving time for move and stop movingTime = resultDistance / moveDistance; isMoveBlocked = true; } else { isMoveBlocked = false; } } // Can't move else { isMoveBlocked = true; } } else { isMoveBlocked = false; } if (isMoveBlocked) { // turn if (dotRight > 1.0f) { SetNextAI(AIType.TurnRight, 90.0f / SpecData.TurnAngle); } else { SetNextAI(AIType.TurnLeft, 90.0f / SpecData.TurnAngle); } } else { SetNextAI(AIType.Move, movingTime); } } } } // Behind area else { // turn if (dotRight > 1.0f) { SetNextAI(AIType.TurnRight, 90.0f / SpecData.TurnAngle); } else { SetNextAI(AIType.TurnLeft, 90.0f / SpecData.TurnAngle); } } if (this.CurrentAction != Action.Idle) { ActionIdle(); } MoveStop(); } }
/// <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> /// creates a player for level. /// reads an player information file(.spec) and configures the player class. /// The read player class is stored in the list. /// </summary> /// <param name="info">player information for level</param> /// <param name="sceneParent">3D scene parent node</param> /// <returns>player class for the game</returns> protected GamePlayer CreatePlayer(ref PlayerInLevel info, NodeBase sceneParent) { GamePlayer player = null; GamePlayerSpec spec = LoadPlayerSpec(ref info); switch (PlayerCountInLevel) { case 0: player = new GamePlayer(ref spec, PlayerIndex.One); break; case 1: player = new GamePlayer(ref spec, PlayerIndex.Two); break; default: throw new InvalidOperationException( "Added player count is overflow"); } // adds a player to list. AddPlayer(player); // entries a player in parent scene node. sceneParent.AddChild(player); // sets to rotation axis. Matrix rot = Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)); player.SetRootAxis(rot); // sets the material. RenderMaterial material = new RenderMaterial(); material.alpha = 1.0f; material.diffuseColor = new Color((byte)info.MaterialDiffuseColor.X, (byte)info.MaterialDiffuseColor.Y, (byte)info.MaterialDiffuseColor.Z); material.specularColor = new Color((byte)info.MaterialSpecularColor.X, (byte)info.MaterialSpecularColor.Y, (byte)info.MaterialSpecularColor.Z); material.emissiveColor = new Color((byte)info.MaterialEmissiveColor.X, (byte)info.MaterialEmissiveColor.Y, (byte)info.MaterialEmissiveColor.Z); material.specularPower = info.MaterialSpecularPower; material.vertexColorEnabled = false; material.preferPerPixelLighting = false; player.Material = material; player.ActiveFog = true; player.ActiveLighting = true; // creates a 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(); player.SpawnPoint = Matrix.CreateRotationY(MathHelper.ToRadians(info.SpawnAngle)) * Matrix.CreateTranslation(info.SpawnPoint); return(player); }
/// <summary> /// creates an enemy for level. /// reads an enemy information file(.spec) and configures the enemy class. /// The read enemy class is stored in the list. /// </summary> /// <param name="info">enemy information for level</param> /// <param name="sceneParent">3D scene parent node</param> protected void CreateSpawnEnemy(ref EnemyInLevel info, NodeBase sceneParent) { GameEnemy enemy = null; GameEnemySpec spec = LoadEnemySpec(ref info); // creates an enemy by unit type switch (spec.UnitClass) { case UnitClassId.Tank: enemy = new EnemyTank(ref spec); break; case UnitClassId.LightMech: case UnitClassId.HeavyMech: enemy = new EnemyMech(ref spec); break; case UnitClassId.Boss: enemy = new EnemyBoss(ref spec); break; default: throw new NotSupportedException( "Not supported unit type : " + spec.UnitType); } // sets the material RenderMaterial material = new RenderMaterial(); material.alpha = 1.0f; material.diffuseColor = new Color((byte)info.MaterialDiffuseColor.X, (byte)info.MaterialDiffuseColor.Y, (byte)info.MaterialDiffuseColor.Z); material.specularColor = new Color((byte)info.MaterialSpecularColor.X, (byte)info.MaterialSpecularColor.Y, (byte)info.MaterialSpecularColor.Z); material.emissiveColor = new Color((byte)info.MaterialEmissiveColor.X, (byte)info.MaterialEmissiveColor.Y, (byte)info.MaterialEmissiveColor.Z); material.specularPower = info.MaterialSpecularPower; material.vertexColorEnabled = false; material.preferPerPixelLighting = false; enemy.Material = material; enemy.ActiveFog = true; enemy.ActiveLighting = true; // adds this to the list. enemyList.Add(enemy); // entries this in parent scene node. sceneParent.AddChild(enemy); // sets to rotate axis. if (spec.UnitType == UnitTypeId.Tiger) { enemy.SetRootAxis( Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f)) * Matrix.CreateRotationZ(MathHelper.ToRadians(90.0f))); } else { enemy.SetRootAxis(Matrix.CreateRotationX(MathHelper.ToRadians(-90.0f))); } // sets to stage spawn position. enemy.SpawnPoint = Matrix.CreateRotationY(MathHelper.ToRadians(info.SpawnAngle)) * Matrix.CreateTranslation(info.SpawnPoint); // activate draw culling. enemy.EnableCulling = true; // creates a collision data. { Vector3 centerPos = Vector3.Transform( new Vector3(0.0f, spec.MechRadius, 0.0f), Matrix.Invert(enemy.RootAxis)); CollideSphere collide = new CollideSphere(centerPos, spec.MechRadius); enemy.SetCollide(collide); } // creates a game event. switch (info.SpawnType) { case SpawnTypeId.Time: { FrameworkCore.GameEventManager.AddEvent( new GameTimeEvent(info.SpawnTime, enemy, false)); } break; case SpawnTypeId.Area: { FrameworkCore.GameEventManager.AddEvent( new GameAreaEvent(info.SpawnPoint, info.SpawnRadius, enemy, false)); } break; } // sets start A.I. enemy.SetStartAI(info.StartAi, info.StartAiTime); }