Exemplo n.º 1
0
        public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
        {
            var self = init.Self;
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <BodyOrientation>();

            // TODO: Carry orientation over from the parent instead of just facing
            var bodyFacing = init.Contains <DynamicFacingInit>() ? init.Get <DynamicFacingInit, Func <int> >()()
                                : init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : 0;

            facing = WAngle.FromFacing(Turreted.TurretFacingFromInit(init, 0)());

            // Calculate final position
            var throwRotation = WRot.FromFacing(Game.CosmeticRandom.Next(1024));
            var throwDistance = Game.CosmeticRandom.Next(info.MinThrowRange.Length, info.MaxThrowRange.Length);

            initialPos = pos = info.Offset.Rotate(body.QuantizeOrientation(self, WRot.FromFacing(bodyFacing)));
            finalPos   = initialPos + new WVec(throwDistance, 0, 0).Rotate(throwRotation);
            angle      = new WAngle(Game.CosmeticRandom.Next(info.MinThrowAngle.Angle, info.MaxThrowAngle.Angle));
            length     = (finalPos - initialPos).Length / info.Velocity;

            // Facing rotation
            rotation = WAngle.FromFacing(WDist.FromPDF(Game.CosmeticRandom, 2).Length *info.TurnSpeed / 1024);

            var anim = new Animation(init.World, rs.GetImage(self), () => facing.Angle / 4);

            anim.PlayRepeating(info.Anim);
            rs.Add(new AnimationWithOffset(anim, () => pos, null));
        }
Exemplo n.º 2
0
        public ThrowsParticle(ActorInitializer init, ThrowsParticleInfo info)
        {
            var self = init.Self;
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <BodyOrientation>();

            // TODO: Carry orientation over from the parent instead of just facing
            var dynamicFacingInit = init.GetOrDefault <DynamicFacingInit>();
            var bodyFacing        = dynamicFacingInit != null?dynamicFacingInit.Value() : init.GetValue <FacingInit, WAngle>(WAngle.Zero);

            facing = TurretedInfo.WorldFacingFromInit(init, info, WAngle.Zero)();

            // Calculate final position
            var throwRotation = WRot.FromYaw(new WAngle(Game.CosmeticRandom.Next(1024)));
            var throwDistance = Game.CosmeticRandom.Next(info.MinThrowRange.Length, info.MaxThrowRange.Length);

            initialPos = pos = info.Offset.Rotate(body.QuantizeOrientation(self, WRot.FromYaw(bodyFacing)));
            finalPos   = initialPos + new WVec(throwDistance, 0, 0).Rotate(throwRotation);
            angle      = new WAngle(Game.CosmeticRandom.Next(info.MinThrowAngle.Angle, info.MaxThrowAngle.Angle));
            length     = (finalPos - initialPos).Length / info.Velocity;

            // WAngle requires positive inputs, so track the speed and direction separately
            var rotationSpeed = WDist.FromPDF(Game.CosmeticRandom, 2).Length *info.TurnSpeed.Angle / 1024;

            direction = rotationSpeed < 0 ? -1 : 1;
            rotation  = new WAngle(Math.Abs(rotationSpeed));

            var anim = new Animation(init.World, rs.GetImage(self), () => facing);

            anim.PlayRepeating(info.Anim);
            rs.Add(new AnimationWithOffset(anim, () => pos, null));
        }