BulletMLLib.Bullet.InitTopNode C# (CSharp) Method

InitTopNode() public method

Initialize this bullet with a top level node
public InitTopNode ( BulletMLLib.BulletMLNode rootNode ) : void
rootNode BulletMLLib.BulletMLNode This is a top level node... find the first "top" node and use it to define this bullet
return void
        public void InitTopNode(BulletMLNode rootNode)
        {
            System.Diagnostics.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 top bullet
              Bullet newDude = _bulletManager.CreateBullet(this, true);

              //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);
              }
        }

Usage Example

Esempio n. 1
0
    void Start()
    {
        // Read pattern file
        // We can optimize this later, making it read
        // every pattern once and storing it somewhere
        pattern = new BulletPattern();
        //pattern.ParseXML(Application.dataPath + "/BulletPatterns/" + PatternFile.name + ".xml");
        //pattern.ParseXML(PatternFile.name + ".xml");
        pattern.ParseXML (patternFile);

        // Find the bullet manager
        // (we need this for the root bullet)
        BulletManagerScript bManager = FindObjectOfType<BulletManagerScript>();

        // Instantiate root bullet
        rootBullet = new BulletObject(bManager);
        // Set its initial position
        rootBullet.X = transform.position.x;
        rootBullet.Y = transform.position.y;
        // Assign its pattern
        rootBullet.InitTopNode(pattern.RootNode);
    }