コード例 #1
0
        /// <summary>
        /// Given a node, pull the direction nodes out from underneath it and store them if necessary
        /// </summary>
        /// <param name="taskToCheck">task to check if has a child direction node.</param>
        private void GetDirectionTasks(BulletMLTask taskToCheck)
        {
            if (null == taskToCheck)
            {
                return;
            }

            //check if the dude has a direction node
            DirectionNode dirNode = taskToCheck.Node.GetChild(ENodeName.direction) as DirectionNode;

            if (null != dirNode)
            {
                //check if it is a sequence type of node
                if (ENodeType.sequence == dirNode.NodeType)
                {
                    //do we need a sequence node?
                    if (null == SequenceDirectionTask)
                    {
                        //store it in the sequence direction node
                        SequenceDirectionTask = new SetDirectionTask(dirNode as DirectionNode, taskToCheck);
                    }
                }
                else
                {
                    //else do we need an initial node?
                    if (null == InitialDirectionTask)
                    {
                        //store it in the initial direction node
                        InitialDirectionTask = new SetDirectionTask(dirNode as DirectionNode, taskToCheck);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// this sets up the task to be run.
        /// </summary>
        /// <param name="bullet">Bullet.</param>
        protected override void SetupTask(Bullet bullet)
        {
            RunDelta = 0;

            //set the time length to run this dude
            Duration = Node.GetChildValue(ENodeName.term, this, bullet);

            //check for divide by 0
            if (0.0f == Duration)
            {
                Duration = 1.0f;
            }

            //Get the amount to change direction from the nodes
            DirectionNode dirNode = Node.GetChild(ENodeName.direction) as DirectionNode;

            NodeDirection = dirNode.GetValue(this, bullet) * (float)Math.PI / 180.0f;             //also make sure to convert to radians

            //How do we want to change direction?
            ChangeType = dirNode.NodeType;
        }
コード例 #3
0
ファイル: SetDirectionTask.cs プロジェクト: JokieW/pewpew
 /// <summary>
 /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
 /// </summary>
 /// <param name="node">Node.</param>
 /// <param name="owner">Owner.</param>
 public SetDirectionTask(DirectionNode node, BulletMLTask owner)
     : base(node, owner)
 {
     System.Diagnostics.Debug.Assert(null != Node);
     System.Diagnostics.Debug.Assert(null != Owner);
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
 /// </summary>
 /// <param name="node">Node.</param>
 /// <param name="owner">Owner.</param>
 public SetDirectionTask(DirectionNode node, BulletMLTask owner)
     : base(node, owner)
 {
     Debug.Assert(null != Node);
     Debug.Assert(null != Owner);
 }
コード例 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
 /// </summary>
 /// <param name="node">Node.</param>
 /// <param name="owner">Owner.</param>
 public SetDirectionTask(DirectionNode node, BulletMLTask owner) : base(node, owner)
 {
     Debug.Assert(null != Node);
     Debug.Assert(null != Owner);
 }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BulletMLLib.BulletMLTask"/> class.
 /// </summary>
 /// <param name="node">Node.</param>
 /// <param name="owner">Owner.</param>
 public SetDirectionTask(DirectionNode node, BulletMLTask owner) : base(node, owner)
 {
     System.Diagnostics.Debug.Assert(null != Node);
     System.Diagnostics.Debug.Assert(null != Owner);
 }
コード例 #7
0
        /// <summary>
        /// this sets up the task to be run.
        /// </summary>
        /// <param name="bullet">Bullet.</param>
        protected override void SetupTask(Bullet bullet)
        {
            //set the time length to run this dude
            startDuration = Node.GetChildValue(ENodeName.term, this);

            //check for divide by 0
            if (0.0f == startDuration)
            {
                startDuration = 1.0f;
            }

            // Remove the 60 FPS limit (or at least try, ChangeDirection is very, very sensitive to frame variation)
            float ratio = TimeFix.Framerate / 60f;

            startDuration *= ratio;

            Duration = startDuration;

            //Get the amount to change direction from the nodes
            DirectionNode dirNode = Node.GetChild(ENodeName.direction) as DirectionNode;
            float         value   = dirNode.GetValue(this) * (float)Mathf.PI / 180.0f;   //also make sure to convert to radians

            //How do we want to change direction?
            ENodeType changeType = dirNode.NodeType;

            switch (changeType)
            {
            case ENodeType.sequence:
            {
                //We are going to add this amount to the direction every frame
                DirectionChange = value;
            }
            break;

            case ENodeType.absolute:
            {
                //We are going to go in the direction we are given, regardless of where we are pointing right now
                DirectionChange = value - bullet.Direction;
            }
            break;

            case ENodeType.relative:
            {
                //The direction change will be relative to our current direction
                DirectionChange = value;
            }
            break;

            default:
            {
                //the direction change is to aim at the enemy
                DirectionChange = ((value + bullet.GetAimDir()) - bullet.Direction);
            }
            break;
            }

            //keep the direction between 0 and 360
            if (DirectionChange > Mathf.PI)
            {
                DirectionChange -= 2 * (float)Mathf.PI;
            }
            else if (DirectionChange < -Mathf.PI)
            {
                DirectionChange += 2 * (float)Mathf.PI;
            }

            //The sequence type of change direction is unaffected by the duration
            if (changeType != ENodeType.sequence)
            {
                //Divide by the duration so we ease into the direction change
                DirectionChange /= Duration;
            }
        }