/// <summary>
        /// Handles a Danmaku collision. Only ever called with Danmaku that pass the filter.
        /// </summary>
        /// <param name="danmaku">the danmaku that hit the collider.</param>
        /// <param name="info">additional information about the collision</param>
        protected override void DanmakuCollision(Danmaku danmaku, RaycastHit2D info)
        {
            if (affected.Contains(danmaku))
            {
                return;
            }
            float baseAngle = angle.Value;

            switch (rotationMode)
            {
            case RotationMode.Relative:
                baseAngle += danmaku.Rotation;
                break;

            case RotationMode.Object:
                if (Target != null)
                {
                    baseAngle += DanmakuUtil.AngleBetween2D(danmaku.Position, Target.position);
                }
                else
                {
                    Debug.LogWarning("Trying to direct at an object but no Target object assinged");
                }
                break;

            case RotationMode.Absolute:
                break;
            }
            danmaku.Rotation = baseAngle;
            affected.Add(danmaku);
        }
        /// <summary>
        /// Handles a Danmaku collision. Only ever called with Danmaku that pass the filter.
        /// </summary>
        /// <param name="danmaku">the danmaku that hit the collider.</param>
        /// <param name="info">additional information about the collision</param>
        protected override void DanmakuCollision(Danmaku danmaku,
                                                 RaycastHit2D info)
        {
            if (affected.Contains(danmaku))
            {
                return;
            }
            if (rotationMode == RotationType.Reflection)
            {
                Vector2 normal    = info.normal;
                Vector2 direction = danmaku.direction;
                danmaku.Direction = direction -
                                    2 * Vector2.Dot(normal, direction) * normal;
                affected.Add(danmaku);
                return;
            }

            float baseAngle = angle;

            switch (rotationMode)
            {
            case RotationType.Relative:
                baseAngle += danmaku.Rotation;
                break;

            case RotationType.Object:
                if (Target != null)
                {
                    baseAngle += DanmakuUtil.AngleBetween2D(
                        danmaku.Position,
                        Target.position);
                }
                else
                {
                    Debug.LogWarning(
                        "Trying to direct at an object but no Target object assinged");
                }
                break;

            case RotationType.Absolute:
                break;
            }
            danmaku.Rotation = baseAngle;
            affected.Add(danmaku);
        }
Beispiel #3
0
        protected override void UpdateSourcePoints(Vector2 position, float rotation)
        {
            SourcePoints.Clear();
            int     edge      = 0;
            float   edgeRot   = 90f + rotation;
            float   edgeDelta = 360f / EdgeCount;
            Vector2 current   = position + Size * Util.OnUnitCircle(edgeRot);
            Vector2 next      = position + Size * Util.OnUnitCircle(edgeRot + edgeDelta);

            edgeRot += edgeDelta;
            while (edge <= edgeCount)
            {
                Vector2 diff = (next - current) / (pointsPerEdge);
                float   rot  = rotation;
                switch (type)
                {
                case RotationType.None:
                case RotationType.Radial:
                    break;

                case RotationType.Tangential:
                    rot = edgeRot - 0.5f * edgeDelta;
                    break;

                case RotationType.Normal:
                    rot = edgeRot - 90f - 0.5f * edgeDelta;
                    break;
                }
                for (int i = 0; i < PointsPerEdge; i++)
                {
                    Vector2 currentPos = current + i * diff;
                    if (Type == RotationType.Radial)
                    {
                        rot = DanmakuUtil.AngleBetween2D(position, currentPos);
                    }
                    SourcePoints.Add(new SourcePoint(currentPos, rot));
                }
                edge++;
                edgeRot += edgeDelta;
                current  = next;
                next     = position + Size * Util.OnUnitCircle(edgeRot);
            }
        }
        /// <summary>
        /// Updates the Danmaku controlled by the controller instance.
        /// </summary>
        /// <param name="danmaku">the bullet to update.</param>
        /// <param name="dt">the change in time since the last update</param>
        public void Update(Danmaku danmaku, float dt)
        {
            float time = danmaku.Time;

            if (time >= Delay && time - dt <= Delay)
            {
                float baseAngle = Angle.Value;
                switch (RotationMode)
                {
                case RotationMode.Relative:
                    baseAngle += danmaku.Rotation;
                    break;

                case RotationMode.Object:
                    baseAngle += DanmakuUtil.AngleBetween2D(danmaku.Position, Target.position);
                    break;

                case RotationMode.Absolute:
                    break;
                }
                danmaku.Rotation = baseAngle;
            }
        }
 public void Update(Danmaku danmaku, float dt)
 {
     danmaku.AngularSpeed = 0f;
     danmaku.Rotation     = DanmakuUtil.AngleBetween2D(danmaku.position, Target.position);
 }