Ejemplo n.º 1
0
        /// <summary>
        /// Given a node, pull the direction nodes out from underneath it and store them if necessary.
        /// </summary>
        /// <param name="taskToCheck">task to check if has a child direction node.</param>
        private void GetDirectionTasks(BulletMLTask taskToCheck)
        {
            // Check if this fire task has a direction node
            var directionNode = taskToCheck?.Node.GetChild(NodeName.direction) as DirectionNode;

            if (directionNode == null)
            {
                return;
            }

            if (DirectionTask == null)
            {
                DirectionTask = new DirectionTask(directionNode, taskToCheck);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets up the task to be run.
        /// </summary>
        /// <param name="bullet">The bullet.</param>
        protected override void SetupTask(Bullet bullet)
        {
            // Get the direction to shoot the bullet

            // Does this fire node contain a direction node?
            if (DirectionTask != null)
            {
                // Set the fire direction to the "initial" value
                var newBulletDirection = DirectionTask.GetNodeValue(bullet);

                switch (DirectionTask.Node.NodeType)
                {
                case NodeType.absolute:
                {
                    // The new bullet points right at a particular direction
                    FireDirection = newBulletDirection;
                }
                break;

                case NodeType.relative:
                {
                    // The new bullet's direction will be relative to the old bullet's one
                    FireDirection = MathHelper.ToDegrees(bullet.Direction) + newBulletDirection;
                }
                break;

                case NodeType.aim:
                {
                    // Aim the bullet at the player
                    FireDirection = MathHelper.ToDegrees(bullet.GetAimDirection()) + newBulletDirection;
                }
                break;

                case NodeType.sequence:
                {
                    // The new bullet's direction will be relative to the last fired bullet's one
                    if (_isRunning)
                    {
                        var lastFireDirection = MathHelper.ToDegrees(_lastFireDirection);
                        FireDirection = lastFireDirection + newBulletDirection;
                    }
                    else
                    {
                        var lastSetupDirection = MathHelper.ToDegrees(_lastSetupDirection);
                        FireDirection = lastSetupDirection + newBulletDirection;
                    }
                }
                break;

                default:
                {
                    // Aim the bullet at the player
                    FireDirection = MathHelper.ToDegrees(bullet.GetAimDirection()) + newBulletDirection;
                }
                break;
                }
            }
            else
            {
                // There isn't direction task, so just aim at the player.
                FireDirection = MathHelper.ToDegrees(bullet.GetAimDirection());
            }

            // Convert from degrees to radians
            FireDirection = MathHelper.ToRadians(FireDirection);

            // Set the speed to shoot the bullet

            // Does this fire node contain a speed node?
            if (SpeedTask != null)
            {
                // Set the shoot speed to the "initial" value.
                var newBulletSpeed = SpeedTask.GetNodeValue(bullet);

                switch (SpeedTask.Node.NodeType)
                {
                case NodeType.relative:
                {
                    // The new bullet speed will be relative to the old bullet
                    FireSpeed = bullet.Speed + newBulletSpeed;
                }
                break;

                case NodeType.sequence:
                {
                    // If there is a sequence node, add the value to the bullet's speed
                    if (_isRunning)
                    {
                        FireSpeed = _lastFireSpeed + newBulletSpeed;
                    }
                    else
                    {
                        FireSpeed = _lastSetupSpeed + newBulletSpeed;
                    }
                }
                break;

                default:
                {
                    // The new bullet shoots at a predeterminde speed
                    FireSpeed = newBulletSpeed;
                }
                break;
                }
            }
            else
            {
                // There is no speed node in the fire node
                FireSpeed = Math.Abs(bullet.Speed) > float.Epsilon ? bullet.Speed : 0f;
            }

            if (ScaleTask != null)
            {
                var newBulletScale = ScaleTask.GetNodeValue(bullet);

                switch (ScaleTask.Node.NodeType)
                {
                case NodeType.relative:
                {
                    FireScale = bullet.Scale + newBulletScale;
                }
                break;

                case NodeType.sequence:
                {
                    if (_isRunning)
                    {
                        FireScale = _lastFireScale + newBulletScale;
                    }
                    else
                    {
                        FireScale = _lastSetupScale + newBulletScale;
                    }
                }
                break;

                default:
                {
                    FireScale = newBulletScale;
                }
                break;
                }
            }
            else
            {
                FireScale = 1f;
            }

            // Store setup direction/speed for sequence type
            _lastSetupDirection = FireDirection;
            _lastSetupSpeed     = FireSpeed;
            _lastSetupScale     = FireScale;
        }