Esempio n. 1
0
        public Laser(ProjectileArgs args, LaserInfo info)
        {
            this.info = info;

            colors = new Color[info.Radius];
            for (var i = 0; i < info.Radius; i++)
            {
                var color = info.Color == Color.Transparent ? args.SourceActor.Owner.Color.RGB : info.Color;
                var bw    = (float)((info.InnerLightness - info.OuterLightness) * i / (info.Radius - 1) + info.OuterLightness) / 0xff;
                var dstR  = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)color.R / 0xff) : 2 * bw * ((float)color.R / 0xff);
                var dstG  = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)color.G / 0xff) : 2 * bw * ((float)color.G / 0xff);
                var dstB  = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)color.B / 0xff) : 2 * bw * ((float)color.B / 0xff);
                colors[i] = Color.FromArgb((int)(dstR * 0xff), (int)(dstG * 0xff), (int)(dstB * 0xff));
            }

            var direction = args.PassiveTarget - args.Source;

            if (this.info.SegmentLength == 0)
            {
                offsets = new[] { new int2(args.Source.X, args.Source.Y), new int2(args.PassiveTarget.X, args.PassiveTarget.Y) };
            }
            else
            {
                var numSegments = (direction.Length - 1) / info.SegmentLength + 1;
                offsets    = new int2[numSegments + 1];
                offsets[0] = new int2(args.Source.X, args.Source.Y);
                offsets[offsets.Length - 1] = new int2(args.PassiveTarget.X, args.PassiveTarget.Y);

                for (var i = 1; i < numSegments; i++)
                {
                    var segmentStart = direction / numSegments * i;
                    offsets[i] = new int2(args.Source.X + segmentStart.X, args.Source.Y + segmentStart.Y);

                    if (info.Distortion != 0)
                    {
                        offsets[i] = new int2(
                            offsets[i].X + Game.CosmeticRandom.Next(-info.Distortion / 2, info.Distortion / 2),
                            offsets[i].Y + Game.CosmeticRandom.Next(-info.Distortion / 2, info.Distortion / 2));
                    }
                }
            }

            args.Weapon.Impact(Target.FromPos(args.PassiveTarget), args.SourceActor, args.DamageModifiers);
        }
Esempio n. 2
0
File: Laser.cs Progetto: spooky/KKnD
        public Laser(ProjectileArgs args, LaserInfo info)
        {
            this.info = info;

            colors = new Color[info.Radius];
            for (var i = 0; i < info.Radius; i++)
            {
                var color = info.Color == Color.Transparent ? args.SourceActor.Owner.Color : info.Color;
                var bw    = (float)((info.InnerLightness - info.OuterLightness) * i / (info.Radius - 1) + info.OuterLightness) / 0xff;
                var dstR  = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)color.R / 0xff) : 2 * bw * ((float)color.R / 0xff);
                var dstG  = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)color.G / 0xff) : 2 * bw * ((float)color.G / 0xff);
                var dstB  = bw > .5 ? 1 - (1 - 2 * (bw - .5)) * (1 - (float)color.B / 0xff) : 2 * bw * ((float)color.B / 0xff);
                colors[i] = Color.FromArgb((int)(dstR * 0xff), (int)(dstG * 0xff), (int)(dstB * 0xff));
            }

            var direction = args.PassiveTarget - args.Source;

            if (info.Distortion != 0 || info.DistortionAnimation != 0)
            {
                leftVector = new WVec(direction.Y, -direction.X, 0);
                if (leftVector.Length != 0)
                {
                    leftVector = 1024 * leftVector / leftVector.Length;
                }

                upVector = new WVec(
                    -direction.X * direction.Z,
                    -direction.Z * direction.Y,
                    direction.X * direction.X + direction.Y * direction.Y);
                if (upVector.Length != 0)
                {
                    upVector = 1024 * upVector / upVector.Length;
                }

                random = args.SourceActor.World.SharedRandom;
            }

            if (this.info.SegmentLength == WDist.Zero)
            {
                offsets = new[] { args.Source, args.PassiveTarget };
            }
            else
            {
                var numSegments = (direction.Length - 1) / info.SegmentLength.Length + 1;
                offsets    = new WPos[numSegments + 1];
                offsets[0] = args.Source;
                offsets[offsets.Length - 1] = args.PassiveTarget;

                for (var i = 1; i < numSegments; i++)
                {
                    var segmentStart = direction / numSegments * i;
                    offsets[i] = args.Source + segmentStart;

                    if (info.Distortion != 0)
                    {
                        var angle      = WAngle.FromDegrees(random.Next(360));
                        var distortion = random.Next(info.Distortion);

                        var offset = distortion * angle.Cos() * leftVector / (1024 * 1024)
                                     + distortion * angle.Sin() * upVector / (1024 * 1024);

                        offsets[i] += offset;
                    }
                }
            }

            args.Weapon.Impact(Target.FromPos(args.PassiveTarget), args.SourceActor);
        }