示例#1
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)
        {
            //Find which direction to shoot the new bullet
            if (DirNode != null)
            {
                //get the direction continade in the node
                float newBulletDirection = (int)DirNode.GetValue(this) * (float)Math.PI / (float)180;
                switch (DirNode.NodeType)
                {
                case ENodeType.sequence:
                {
                    bullet.GetFireData().srcDir += newBulletDirection;
                }
                break;

                case ENodeType.absolute:
                {
                    bullet.GetFireData().srcDir = newBulletDirection;
                }
                break;

                case ENodeType.relative:
                {
                    bullet.GetFireData().srcDir = newBulletDirection + bullet.Direction;
                }
                break;

                default:
                {
                    bullet.GetFireData().srcDir = newBulletDirection + bullet.GetAimDir();
                }
                break;
                }
            }
            else
            {
                //otherwise if no direction node, aim the bullet at the bad guy
                bullet.GetFireData().srcDir = bullet.GetAimDir();
            }

            //Create the new bullet
            Bullet newBullet = bullet.MyBulletManager.CreateBullet();

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

            //initialize the bullet from a reference node, or our bullet node
            if (RefNode != null)
            {
                //Add an empty task to the bullet and populate it with all the params
                BulletMLTask bulletBlankTask = newBullet.CreateTask();

                //Add all the params to the new task we just added to that bullet
                for (int i = 0; i < RefNode.ChildNodes.Count; i++)
                {
                    bulletBlankTask.ParamList.Add(RefNode.ChildNodes[i].GetValue(this));
                }

                //init the bullet now that all our stuff is prepopulated
                BulletMLNode subNode = bullet.MyNode.GetRootNode().FindLabelNode(RefNode.Label, ENodeName.bullet);
                newBullet.Init(subNode);
            }
            else
            {
                //if there is no ref node, there has to be  bullet node
                newBullet.Init(BulletNode);
            }

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

            //set the owner of the new bullet to this dude
            newBullet._tasks[0].Owner = this;

            //set the direction of the new bullet
            newBullet.Direction = bullet.GetFireData().srcDir;

            //Has the speed for new bullets been set in the source bullet yet?
            if (!bullet.GetFireData().speedInit&& newBullet.GetFireData().speedInit)
            {
                bullet.GetFireData().srcSpeed  = newBullet.Velocity;
                bullet.GetFireData().speedInit = true;
            }
            else
            {
                //find the speed for new bullets and store it in the source bullet
                if (SpeedNode != null)
                {
                    //Get the speed from a speed node
                    float newBulletSpeed = SpeedNode.GetValue(this);
                    if (SpeedNode.NodeType == ENodeType.sequence || SpeedNode.NodeType == ENodeType.relative)
                    {
                        bullet.GetFireData().srcSpeed += newBulletSpeed;
                    }
                    else
                    {
                        bullet.GetFireData().srcSpeed = newBulletSpeed;
                    }
                }
                else
                {
                    if (!newBullet.GetFireData().speedInit)
                    {
                        bullet.GetFireData().srcSpeed = 1;
                    }
                    else
                    {
                        bullet.GetFireData().srcSpeed = newBullet.Velocity;
                    }
                }
            }

            newBullet.GetFireData().speedInit = false;
            newBullet.Velocity = bullet.GetFireData().srcSpeed;

            TaskFinished = true;
            return(ERunStatus.End);
        }
示例#2
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 BulletMLAccel(BulletMLNode node, BulletMLTask owner) : base(node, owner)
 {
     Debug.Assert(null != Node);
     Debug.Assert(null != Owner);
 }
示例#3
0
        /// <summary>
        /// Parses a bulletml document into this bullet pattern
        /// </summary>
        /// <param name="xmlFileName">Xml file name.</param>
        public bool ParseXML(string xmlFileName)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.DtdProcessing = DtdProcessing.Ignore;

            using (XmlReader reader = XmlReader.Create(xmlFileName, settings))
            {
                //Open the file.
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(reader);
                XmlNode rootXmlNode = xmlDoc.DocumentElement;

                //make sure it is actually an xml node
                if (rootXmlNode.NodeType == XmlNodeType.Element)
                {
                    //eat up the name of that xml node
                    string strElementName = rootXmlNode.Name;
                    if (("bulletml" != strElementName) || !rootXmlNode.HasChildNodes)
                    {
                        //The first node HAS to be bulletml
                        Debug.Assert(false);
                        return(false);
                    }

                    //Create the root node of the bulletml tree
                    RootNode = new BulletMLNode();

                    //Read in the whole bulletml tree
                    if (!RootNode.Parse(rootXmlNode, null))
                    {
                        //an error ocurred reading in the tree
                        return(false);
                    }
                    Debug.Assert(ENodeName.bulletml == RootNode.Name);

                    //Find what kind of pattern this is: horizontal or vertical
                    XmlNamedNodeMap mapAttributes = rootXmlNode.Attributes;
                    for (int i = 0; i < mapAttributes.Count; i++)
                    {
                        //will only have the name attribute
                        string strName  = mapAttributes.Item(i).Name;
                        string strValue = mapAttributes.Item(i).Value;
                        if ("type" == strName)
                        {
                            //if  this is a top level node, "type" will be veritcal or horizontal
                            Orientation = StringToPatternType(strValue);
                        }
                    }
                }
                else
                {
                    //should be an xml node!!!
                    Debug.Assert(false);
                    return(false);
                }
            }

            //grab that filename
            Filename = xmlFileName;
            return(true);
        }
示例#4
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 Parse(BulletMLNode myNode, Bullet bullet)
        {
            Debug.Assert(null != myNode);
            Debug.Assert(null != bullet);

            foreach (BulletMLNode childNode in myNode.ChildNodes)
            {
                //construct the correct type of node
                switch (childNode.Name)
                {
                case ENodeName.repeat:
                {
                    Parse(childNode, bullet);
                }
                break;

                case ENodeName.action:
                {
                    int repeatNum = 1;

                    //find how many times to repeat this action
                    BulletMLNode RepeatNode = childNode.FindParentNode(ENodeName.repeat);
                    if (null != RepeatNode)
                    {
                        repeatNum = (int)RepeatNode.GetChildValue(ENodeName.times, this);
                    }

                    BulletMLAction task = new BulletMLAction(repeatNum, myNode, this);
                    ChildTasks.Add(task);
                    task.Parse(childNode, bullet);
                }
                break;

                case ENodeName.actionRef:
                {
                    //find the referenced node
                    BulletMLNode refNode = myNode.GetRootNode().FindLabelNode(childNode.Label, ENodeName.action);

                    //find how many times to repeat the referenced action
                    int          repeatNum  = 1;
                    BulletMLNode RepeatNode = myNode.FindParentNode(ENodeName.repeat);
                    if (null != RepeatNode)
                    {
                        repeatNum = (int)RepeatNode.GetChildValue(ENodeName.times, this);
                    }

                    BulletMLAction task = new BulletMLAction(repeatNum, refNode, this);
                    ChildTasks.Add(task);

                    for (int i = 0; i < childNode.ChildNodes.Count; i++)
                    {
                        task.ParamList.Add(childNode.ChildNodes[i].GetValue(this));
                    }

                    task.Parse(refNode, bullet);
                }
                break;

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

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

                case ENodeName.fire:
                {
                    ChildTasks.Add(new BulletMLFire(childNode, this));
                }
                break;

                case ENodeName.fireRef:
                {
                    //find the node that was referenced
                    BulletMLNode refNode = myNode.GetRootNode().FindLabelNode(childNode.Label, ENodeName.fire);
                    BulletMLFire fire    = new BulletMLFire(refNode, this);
                    ChildTasks.Add(fire);

                    for (int i = 0; i < childNode.ChildNodes.Count; i++)
                    {
                        fire.ParamList.Add(childNode.ChildNodes[i].GetValue(this));
                    }
                }
                break;

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

                case ENodeName.speed:
                {
                    //speed nodes are special, just pull the value out and set up the bullet
                    bullet.GetFireData().speedInit = true;
                    bullet.Velocity = childNode.GetValue(this);
                }
                break;

                case ENodeName.direction:
                {
                    ChildTasks.Add(new BulletMLSetDirection(childNode, this));
                }
                break;

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

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

            //After all the nodes are read in, initialize the node
            Init();
        }
示例#5
0
 /// BulletMLの弾幕定義を自分にセット
 public void SetBullet(BulletMLNode tree)
 {
     InitTop(tree);
 }