This is the bullet class that outside assemblies will interact with. Just inherit from this class and override the abstract functions!
Inheritance: Danmaku_no_Kyojin.Entities.SpriteEntity
Exemplo n.º 1
0
        public override ERunStatus Run(Bullet bullet)
        {
            ENodeType ENodeType = Node.NodeType;
            float value = (float)(Node.GetValue(this) * Math.PI / 180);

            switch (ENodeType)
            {
                case ENodeType.sequence:
                {
                    bullet.Direction = bullet.GetFireData().srcDir + value;
                }
                break;
                case ENodeType.absolute:
                {
                    bullet.Direction = value;
                }
                break;
                case ENodeType.relative:
                {
                    bullet.Direction = bullet.Direction + value;
                }
                break;
                default:
                {
                    bullet.Direction = bullet.GetAimDir() + value;
                }
                break;
            }

            TaskFinished = true;
            return ERunStatus.End;
        }
Exemplo 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)
 {
     //remove the bullet via the bullet manager interface
     IBulletManager manager = bullet.MyBulletManager;
     Debug.Assert(null != manager);
     manager.RemoveBullet(bullet);
     return ERunStatus.End;
 }
Exemplo n.º 3
0
 /// <summary>
 /// 弾が消えたときにライブラリから呼び出される
 /// </summary>
 public void RemoveBullet(Bullet deadBullet)
 {
     Mover myMover = deadBullet as Mover;
     if (myMover != null)
     {
         myMover.used = false;
     }
 }
Exemplo n.º 4
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)
 {
     Duration--;
     if (Duration >= 0)
     {
         return ERunStatus.Stop;
     }
     else
     {
         TaskFinished = true;
         return ERunStatus.End;
     }
 }
Exemplo n.º 5
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)
        {
            //is this the fisrt time running this task?
            if (InitialRun)
            {
                //if this is the first time, set the accelerataion we are gonna add to the bullet
                InitialRun = false;
                Duration = (int)Node.GetChildValue(ENodeName.term, this);
                switch (Node.NodeType)
                {
                    case ENodeType.sequence:
                        {
                        _Acceleration.X = Node.GetChildValue(ENodeName.horizontal, this);
                        _Acceleration.Y = Node.GetChildValue(ENodeName.vertical, this);
                        }
                        break;

                    case ENodeType.relative:
                        {
                        _Acceleration.X = Node.GetChildValue(ENodeName.horizontal, this) / Duration;
                        _Acceleration.Y = Node.GetChildValue(ENodeName.vertical, this) / Duration;
                        }
                        break;

                    default:
                        {
                        _Acceleration.X = (Node.GetChildValue(ENodeName.horizontal, this) - bullet.Acceleration.X) / Duration;
                        _Acceleration.Y = (Node.GetChildValue(ENodeName.vertical, this) - bullet.Acceleration.Y) / Duration;
                        }
                        break;
                }
            }

            //Add the acceleration to the bullet
            bullet.Acceleration += _Acceleration;

            //decrement the amount if time left to run and return End when this task is finished
            Duration--;
            if (Duration <= 0)
            {
                TaskFinished = true;
                return ERunStatus.End;
            }
            else
            {
                //since this task isn't finished, run it again next time
                return ERunStatus.Continue;
            }
        }
Exemplo n.º 6
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)
        {
            if (InitialRun)
            {
                InitialRun = false;

                switch (Node.GetChild(ENodeName.speed).NodeType)
                {
                    case ENodeType.sequence:
                    {
                        SpeedChange = Node.GetChildValue(ENodeName.speed, this);
                    }
                    break;

                    case ENodeType.relative:
                    {
                        SpeedChange = Node.GetChildValue(ENodeName.speed, this) / Duration;
                    }
                    break;

                    default:
                    {
                        SpeedChange = (Node.GetChildValue(ENodeName.speed, this) - bullet.Velocity) / Duration;
                    }
                    break;
                }
            }

            bullet.Velocity += SpeedChange;

            Duration--;
            if (Duration <= 0)
            {
                TaskFinished = true;
                return ERunStatus.End;
            }
            else
            {
                return ERunStatus.Continue;
            }
        }
Exemplo n.º 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)
        {
            //run the action until we hit the limit
            while (RepeatNum < RepeatNumMax)
            {
                ERunStatus runStatus = base.Run(bullet);

                //What was the return value from running all teh child actions?
                switch (runStatus)
                {
                    case ERunStatus.End:
                    {
                        //The actions completed successfully, initialize everything and run it again
                        RepeatNum++;
                        base.Init();
                    }
                    break;

                    case ERunStatus.Stop:
                    {
                        //Something in the child tasks paused this action
                        return runStatus;
                    }

                    default:
                    {
                        //One of the child tasks needs to keep running next frame
                        return ERunStatus.Continue;
                    }
                }
            }

            //if it gets here, all the child tasks have been run the correct number of times
            TaskFinished = true;
            return ERunStatus.End;
        }
Exemplo n.º 8
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)
 {
     bullet.Velocity = Node.GetValue(this);
     TaskFinished = true;
     return ERunStatus.End;
 }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
0
        public override ERunStatus Run(Bullet bullet)
        {
            if (InitialRun)
            {
                InitialRun = false;

                //Get the amount to change direction from the nodes
                float value = (float)(Node.GetChildValue(ENodeName.direction, this) * Math.PI / 180); //also make sure to convert to radians

                //How do we want to change direction?
                ChangeType = Node.GetChild(ENodeName.direction).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 = (float)(value - bullet.Direction);
                    }
                    break;

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

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

                //keep the direction between 0 and 360
                if (DirectionChange > Math.PI)
                {
                    DirectionChange -= 2 * (float)Math.PI;
                }
                else if (DirectionChange < -Math.PI)
                {
                    DirectionChange += 2 * (float)Math.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 /= (float)Duration;
                }
            }

            //change the direction of the bullet by the correct amount
            bullet.Direction += DirectionChange;

            //decrement the amount if time left to run and return End when this task is finished
            Duration--;
            if (Duration <= 0)
            {
                TaskFinished = true;
                return ERunStatus.End;
            }
            else
            {
                //since this task isn't finished, run it again next time
                return ERunStatus.Continue;
            }
        }
Exemplo n.º 11
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 virtual ERunStatus Run(Bullet bullet)
        {
            //run all the child tasks
            TaskFinished = true;
            for (int i = 0; i < ChildTasks.Count; i++)
            {
                //is the child task finished running?
                if (!ChildTasks[i].TaskFinished)
                {
                    //Run the child task...
                    ERunStatus childStaus = ChildTasks[i].Run(bullet);
                    if (childStaus == ERunStatus.Stop)
                    {
                        //The child task is paused, so it is not finished
                        TaskFinished = false;
                        return childStaus;
                    }
                    else if (childStaus == ERunStatus.Continue)
                    {
                        //child task needs to do some more work
                        TaskFinished = false;
                    }
                }
            }

            return (TaskFinished ?  ERunStatus.End : ERunStatus.Continue);
        }
Exemplo n.º 12
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();
        }
Exemplo n.º 13
0
 /// <summary>
 /// a mathod to get current position of the player
 /// This is used to target bullets at that position
 /// </summary>
 /// <returns>The position to aim the bullet at</returns>
 /// <param name="targettedBullet">the bullet we are getting a target for</param>
 public Vector2 PlayerPosition(Bullet targettedBullet)
 {
     //just give the player's position
     Debug.Assert(null != GetPlayerPosition);
     return GetPlayerPosition();
 }