/// <summary> /// loads an player's information using spec file (.spec). /// </summary> /// <param name="info">player information for level</param> /// <returns>player's spec information</returns> public static GamePlayerSpec LoadPlayerSpec(ref PlayerInLevel info) { // loads a information of the spawn enemy. GamePlayerSpec spec = new GamePlayerSpec(); spec = (GamePlayerSpec)GameDataSpecManager.Load(info.SpecFilePath, spec.GetType()); return(spec); }
/// <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); }