Exemple #1
0
        public Danmaku Fire(FireData data)
        {
            if (TargetField == null)
            {
                TargetField = this;
            }
            DanmakuField old = data.Field;

            data.Field = TargetField;
            Danmaku danmaku = data.Fire();

            data.Field = old;
            return(danmaku);
        }
 protected void FireSingle(Vector2 position,
                           DynamicFloat rotation)
 {
     if (SubModifier == null)
     {
         data.Position = position;
         data.Rotation = rotation;
         data.Fire();
     }
     else
     {
         SubModifier.OnFire(position, rotation);
     }
 }
        /// <summary>
        /// Fires a single bullet from the bullet's current position.
        /// </summary>
        ///
        /// <remarks>
        /// By default, firing using this method also uses the rotation of the bullet to fire the bullet.
        /// Set <c>useRotation</c> to false to disable this.
        /// </remarks>
        /// <param name="data">the data used to create the .</param>
        /// <param name="useRotation">If set to <c>true</c>, the bullet will use the current rotation of the bullet to fire with.</param>
        public Danmaku Fire(FireData data, bool useRotation = true)
        {
            Vector2      tempPos = data.Position;
            DynamicFloat tempRot = data.Rotation;

            data.Position = Position;
            if (useRotation)
            {
                data.Rotation = Rotation;
            }
            Danmaku danmaku = data.Fire();

            data.Position = tempPos;
            data.Rotation = tempRot;
            return(danmaku);
        }
        public void Fire()
        {
            Vector2      actualPosition = Position;
            DynamicFloat actualRotation = Rotation;

            if (positionSource != null)
            {
                actualPosition = positionSource.position;
            }

            if (rotationSource != null)
            {
                actualRotation = rotationSource.Rotation2D();
            }

            if (targeted)
            {
                if (targetPosition != null)
                {
                    actualRotation += DanmakuUtil.AngleBetween2D(actualPosition, (Vector2)targetPosition);
                }
                else if (targetObject != null)
                {
                    actualRotation += DanmakuUtil.AngleBetween2D(actualPosition, targetObject.position);
                }
            }

            Vector2      tempPos      = Position;
            DynamicFloat tempRotation = Rotation;

            Position = actualPosition;
            Rotation = actualRotation;

            if (modifiers.Count <= 0)
            {
                data.Fire();
            }
            else if (modifiers.Count == 1)
            {
                DanmakuModifier singleModifier = modifiers[0];
                if (singleModifier == null)
                {
                    data.Fire();
                }
                else
                {
                    singleModifier.Fire(data);
                }
            }
            else
            {
                DanmakuModifier[] oldSubModifiers = new DanmakuModifier[modifiers.Count];
                DanmakuModifier   previous = null, current, initial = null;
                for (int i = 0; i < oldSubModifiers.Length; i++)
                {
                    current = modifiers[i];
                    if (current != null)
                    {
                        oldSubModifiers[i] = current.SubModifier;
                        if (previous != null)
                        {
                            previous.SubModifier = current;
                        }
                        else
                        {
                            initial = current;
                        }
                        previous = current;
                    }
                }

                if (initial != null)
                {
                    initial.Fire(data);
                }
                else
                {
                    data.Fire();
                }

                for (int i = 0; i < oldSubModifiers.Length; i++)
                {
                    current = modifiers[i];
                    if (current != null)
                    {
                        current.SubModifier = oldSubModifiers[i];
                    }
                }
            }

            data.Position = tempPos;
            data.Rotation = tempRotation;
        }