Example #1
0
        /// <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 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);
        }
Example #3
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);
        }
Example #4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public GamePlayer(ref GamePlayerSpec spec, PlayerIndex index)
            : base(spec.ModelFilePath)
        {
            this.specData = spec;

            if (this.specData == null)
                throw new ArgumentException("Cannot read player spec file.");
            
            Name = this.specData.UnitType.ToString();
            Life = this.specData.Life;
            MaxLife = this.SpecData.Life;

            this.PlayerIndex = index;

            //  Set game input
            InputComponent input =
                        FrameworkCore.InputManager.GetInputComponent(this.PlayerIndex);

            this.gameInput = new GameInput(input);
            this.gameInput.SetDefaultKey(this.PlayerIndex);

            //  Load Animations
            LoadAnimationData(this.specData.AnimationFolderPath);

            //  Load a default waepon
            CreateWeapon(this.specData.DefaultWeaponFilePath);

            //  Find index of dummy bones
            for (int i = 0; i < ModelData.model.Bones.Count; i++)
            {
                ModelBone bone = ModelData.model.Bones[i];

                if (bone.Name == "HeroPointDummyLeft")
                    this.indexLeftHandWeaponDummy = bone.Index;
                else if (bone.Name == "HeroPointDummyRight")
                    this.indexRightHandWeaponDummy = bone.Index;
                else if (bone.Name == "BoosterDummyLeft")
                    this.indexLeftBoosterDummy = bone.Index;
                else if (bone.Name == "BoosterDummyRight")
                    this.indexRightBoosterDummy = bone.Index;
                else if (bone.Name == "BoosterDummy")
                    this.indexLeftBoosterDummy = bone.Index;
                else if (bone.Name == "L Foot")
                    this.indexLeftFootDummy = bone.Index;
                else if (bone.Name == "R Foot")
                    this.indexRightFootDummy = bone.Index;
            }

            //  The normal map and the specular map effects are applied to “Grund” and 
            //  “Mark” only.
            if (this.UnitType == UnitTypeId.Grund ||
                this.UnitType == UnitTypeId.Mark)
            {
                RenderingCustomEffect += 
                    new EventHandler<RenderingCustomEffectEventArgs>(OnEffectProcess);
            }
        }