Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BulletMLLib.FireTask"/> class.
        /// </summary>
        /// <param name="node">Node.</param>
        /// <param name="owner">Owner.</param>
        public FireTask(FireNode node, BulletMLTask owner) : base(node, owner)
        {
            Debug.Assert(null != Node);
            Debug.Assert(null != Owner);

            NumTimesInitialized = 0;
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BulletMLLib.FireTask"/> class.
        /// </summary>
        /// <param name="node">Node.</param>
        /// <param name="owner">Owner.</param>
        public FireTask(FireNode node, BulletMLTask owner) : base(node, owner)
        {
            System.Diagnostics.Debug.Assert(null != Node);
            System.Diagnostics.Debug.Assert(null != Owner);

            NumTimesInitialized = 0;
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BulletMLLib.FireTask"/> class.
        /// </summary>
        /// <param name="node">Node.</param>
        /// <param name="owner">Owner.</param>
        public FireTask(FireNode node, BulletMLTask owner)
            : base(node, owner)
        {
            Debug.Assert(null != Node);
            Debug.Assert(null != Owner);

            NumTimesInitialized = 0;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BulletMLLib.FireTask"/> class.
        /// </summary>
        /// <param name="node">Node.</param>
        /// <param name="owner">Owner.</param>
        public FireTask(FireNode node, BulletMLTask owner)
            : base(node, owner)
        {
            System.Diagnostics.Debug.Assert(null != Node);
            System.Diagnostics.Debug.Assert(null != Owner);

            NumTimesInitialized = 0;
        }
Beispiel #5
0
        /// <summary>
        /// Validates the node.
        /// Overloaded in child classes to validate that each type of node follows the correct business logic.
        /// This checks stuff that isn't validated by the XML validation
        /// </summary>
        public override void ValidateNode()
        {
            //Find the action node this dude
            Debug.Assert(null != GetRootNode());
            BulletMLNode refNode = GetRootNode().FindLabelNode(Label, ENodeName.fire);

            //make sure we foud something
            if (null == refNode)
            {
                throw new NullReferenceException("Couldn't find the fire node \"" + Label + "\"");
            }

            ReferencedFireNode = refNode as FireNode;
            if (null == ReferencedFireNode)
            {
                throw new NullReferenceException("The BulletMLNode \"" + Label + "\" isn't a fire node");
            }

            //Do not validate the base class of this dude... it will crap out trying to find the bullet node!
        }
Beispiel #6
0
        /// <summary>
        /// Validates the node.
        /// Overloaded in child classes to validate that each type of node follows the correct business logic.
        /// This checks stuff that isn't validated by the XML validation
        /// </summary>
        public override void ValidateNode()
        {
            //Find the action node this dude
            Debug.Assert(null != GetRootNode());
            BulletMLNode refNode = GetRootNode().FindLabelNode(Label, ENodeName.fire);

            //make sure we foud something
            if (null == refNode)
            {
                throw new NullReferenceException("Couldn't find the fire node \"" + Label + "\"");
            }

            ReferencedFireNode = refNode as FireNode;
            if (null == ReferencedFireNode)
            {
                throw new NullReferenceException("The BulletMLNode \"" + Label + "\" isn't a fire node");
            }

            //Do not validate the base class of this dude... it will crap out trying to find the bullet node!
        }
Beispiel #7
0
        /// <summary>
        /// Run this task and all subtasks against a bullet
        /// This is called once a frame during runtime.
        /// </summary>
        /// <returns>ERunStatus: whether this task is done, paused, or still running</returns>
        /// <param name="bullet">The bullet to update this task against.</param>
        public override ERunStatus Run(Bullet bullet)
        {
            //Create the new bullet
            Bullet newBullet = bullet.MyBulletManager.CreateBullet(bullet, false);

            if (newBullet == null)
            {
                //wtf did you do???
                TaskFinished = true;
                return(ERunStatus.End);
            }

            //set the location of the new bullet
            newBullet.X = bullet.X;
            newBullet.Y = bullet.Y;

            //set the direction of the new bullet
            newBullet.Direction = FireDirection;

            //set teh speed of the new bullet
            newBullet.Speed = FireSpeed;

            //initialize the bullet with the bullet node stored in the Fire node
            FireNode myFireNode = Node as FireNode;

            System.Diagnostics.Debug.Assert(null != myFireNode);

            newBullet.InitNode(myFireNode.BulletDescriptionNode);

            // Let the bullet handler initialize the bullet ingame data
            newBullet.InitBullet();

            //set the owner of all the top level tasks for the new bullet to this dude
            foreach (BulletMLTask task in newBullet.Tasks)
            {
                task.Owner = this;
            }

            TaskFinished = true;
            return(ERunStatus.End);
        }
Beispiel #8
0
        /// <summary>
        /// Parse a specified node and bullet into this task
        /// </summary>
        /// <param name="myNode">the node for this dude</param>
        /// <param name="bullet">the bullet this dude is controlling</param>
        public virtual void ParseChildNode(BulletMLNode childNode, Bullet bullet)
        {
            Debug.Assert(null != childNode);
            Debug.Assert(null != bullet);

            //construct the correct type of node
            switch (childNode.Name)
            {
            case ENodeName.repeat:
            {
                //convert the node to an repeatnode
                RepeatNode myRepeatNode = childNode as RepeatNode;

                //create a placeholder bulletmltask for the repeat node
                RepeatTask repeatTask = new RepeatTask(myRepeatNode, this);

                //parse the child nodes into the repeat task
                repeatTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(repeatTask);
            }
            break;

            case ENodeName.action:
            {
                //convert the node to an ActionNode
                ActionNode myActionNode = childNode as ActionNode;

                //create the action task
                ActionTask actionTask = new ActionTask(myActionNode, this);

                //parse the children of the action node into the task
                actionTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(actionTask);
            }
            break;

            case ENodeName.actionRef:
            {
                //convert the node to an ActionNode
                ActionRefNode myActionNode = childNode as ActionRefNode;

                //create the action task
                ActionTask actionTask = new ActionTask(myActionNode, this);

                //add the params to the action task
                for (int i = 0; i < childNode.ChildNodes.Count; i++)
                {
                    actionTask.ParamList.Add(childNode.ChildNodes[i].GetValue(this, bullet));
                }

                //parse the children of the action node into the task
                actionTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(actionTask);
            }
            break;

            case ENodeName.changeSpeed:
            {
                ChildTasks.Add(new ChangeSpeedTask(childNode as ChangeSpeedNode, this));
            }
            break;

            case ENodeName.changeDirection:
            {
                ChildTasks.Add(new ChangeDirectionTask(childNode as ChangeDirectionNode, this));
            }
            break;

            case ENodeName.fire:
            {
                //convert the node to a fire node
                FireNode myFireNode = childNode as FireNode;

                //create the fire task
                FireTask fireTask = new FireTask(myFireNode, this);

                //parse the children of the fire node into the task
                fireTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(fireTask);
            }
            break;

            case ENodeName.fireRef:
            {
                //convert the node to a fireref node
                FireRefNode myFireNode = childNode as FireRefNode;

                //create the fire task
                FireTask fireTask = new FireTask(myFireNode.ReferencedFireNode, this);

                //add the params to the fire task
                for (int i = 0; i < childNode.ChildNodes.Count; i++)
                {
                    fireTask.ParamList.Add(childNode.ChildNodes[i].GetValue(this, bullet));
                }

                //parse the children of the action node into the task
                fireTask.ParseTasks(bullet);

                //store the task
                ChildTasks.Add(fireTask);
            }
            break;

            case ENodeName.wait:
            {
                ChildTasks.Add(new WaitTask(childNode as WaitNode, this));
            }
            break;

            case ENodeName.vanish:
            {
                ChildTasks.Add(new VanishTask(childNode as VanishNode, this));
            }
            break;

            case ENodeName.accel:
            {
                ChildTasks.Add(new AccelTask(childNode as AccelNode, this));
            }
            break;
            }
        }