InitNode() public method

This bullet is fired from another bullet, initialize it from the node that fired it
public InitNode ( BulletMLLib.BulletMLNode subNode ) : void
subNode BulletMLLib.BulletMLNode Sub node that defines this bullet
return void
Esempio n. 1
0
        /// <summary>
        /// Initialize this bullet with a top level node
        /// </summary>
        /// <param name="rootNode">This is a top level node... find the first "top" node and use it to define this bullet</param>
        public void InitTopNode(BulletMLNode rootNode)
        {
            Debug.Assert(null != rootNode);

            //okay find the item labelled 'top'
            bool         bValidBullet = false;
            BulletMLNode topNode      = rootNode.FindLabelNode("top", ENodeName.action);

            if (topNode != null)
            {
                //initialize with the top node we found!
                InitNode(topNode);
                bValidBullet = true;
            }
            else
            {
                //ok there is no 'top' node, so that means we have a list of 'top#' nodes
                for (int i = 1; i < 10; i++)
                {
                    topNode = rootNode.FindLabelNode("top" + i, ENodeName.action);
                    if (topNode != null)
                    {
                        if (!bValidBullet)
                        {
                            //Use this bullet!
                            InitNode(topNode);
                            bValidBullet = true;
                        }
                        else
                        {
                            //Create a new bullet
                            Bullet newDude = _bulletManager.CreateBullet();

                            //set the position to this dude's position
                            newDude.X = this.X;
                            newDude.Y = this.Y;

                            //initialize with the node we found
                            newDude.InitNode(topNode);
                        }
                    }
                }
            }

            if (!bValidBullet)
            {
                //We didnt find a "top" node for this dude, remove him from the game.
                _bulletManager.RemoveBullet(this);
            }
        }
Esempio n. 2
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);
        }