Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <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);
        }