public WithMuzzleFlash(Actor self, WithMuzzleFlashInfo info)
        {
            var render = self.Trait <RenderSprites>();
            var facing = self.TraitOrDefault <IFacing>();

            foreach (var arm in self.TraitsImplementing <Armament>())
            {
                // Skip armaments that don't define muzzles
                if (arm.Info.MuzzleSequence == null)
                {
                    continue;
                }

                foreach (var b in arm.Barrels)
                {
                    var barrel   = b;
                    var turreted = self.TraitsImplementing <Turreted>()
                                   .FirstOrDefault(t => t.Name == arm.Info.Turret);

                    getFacing = turreted != null ? () => turreted.turretFacing :
                                facing != null ? (Func <int>)(() => facing.Facing) : () => 0;

                    var muzzleFlash = new Animation(self.World, render.GetImage(self), getFacing);
                    visible.Add(barrel, false);
                    anims.Add(barrel,
                              new AnimationWithOffset(muzzleFlash,
                                                      () => info.IgnoreOffset ? WVec.Zero : arm.MuzzleOffset(self, barrel),
                                                      () => !visible[barrel],
                                                      () => false,
                                                      p => WithTurret.ZOffsetFromCenter(self, p, 2)));
                }
            }
        }
Exemple #2
0
        public WithMuzzleFlash(Actor self, WithMuzzleFlashInfo info)
        {
            this.info = info;
            var render = self.Trait <RenderSprites>();
            var facing = self.TraitOrDefault <IFacing>();

            var arm = self.TraitsImplementing <Armament>()
                      .Single(a => a.Info.Name == info.Armament);

            foreach (var b in arm.Barrels)
            {
                var barrel   = b;
                var turreted = self.TraitsImplementing <Turreted>()
                               .FirstOrDefault(t => t.Name == arm.Info.Turret);

                getFacing = turreted != null ? () => turreted.turretFacing :
                            facing != null ? (Func <int>)(() => facing.Facing) : () => 0;

                var muzzleFlash = new Animation(render.GetImage(self), getFacing);
                visible.Add(barrel, false);
                anims.Add(barrel,
                          new AnimationWithOffset(muzzleFlash,
                                                  () => arm.MuzzleOffset(self, barrel),
                                                  () => !visible[barrel],
                                                  p => WithTurret.ZOffsetFromCenter(self, p, 2)));
            }
        }
Exemple #3
0
        public WithRotor(Actor self, WithRotorInfo info)
        {
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <IBodyOrientation>();

            rotorAnim = new Animation(rs.GetImage(self));
            rotorAnim.PlayRepeating("rotor");
            rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
                                                          () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
                                                          null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
        }
Exemple #4
0
        public WithIdleOverlay(Actor self, WithIdleOverlayInfo info)
        {
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <IBodyOrientation>();

            buildComplete = !self.HasTrait <Building>();            // always render instantly for units
            overlay       = new Animation(rs.GetImage(self));
            overlay.PlayRepeating(info.Sequence);
            rs.anims.Add("idle_overlay_{0}".F(info.Sequence),
                         new AnimationWithOffset(overlay,
                                                 () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
                                                 () => !buildComplete, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
        }
Exemple #5
0
        public WithRotor(Actor self, WithRotorInfo info)
        {
            this.info = info;
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <IBodyOrientation>();

            movement = self.Trait <IMove>();

            rotorAnim = new Animation(self.World, rs.GetImage(self));
            rotorAnim.PlayRepeating(info.Sequence);
            rs.Add(info.Id, new AnimationWithOffset(rotorAnim,
                                                    () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
                                                    null, () => false, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
        }
        public WithHarvestAnimation(Actor self, WithHarvestAnimationInfo info)
        {
            this.info = info;
            var rs   = self.Trait <RenderSprites>();
            var body = self.Trait <IBodyOrientation>();

            anim = new Animation(self.World, rs.GetImage(self), RenderSimple.MakeFacingFunc(self));
            anim.Play(info.Sequence);
            rs.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim,
                                                                           () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
                                                                           () => !visible,
                                                                           () => false,
                                                                           p => WithTurret.ZOffsetFromCenter(self, p, 0)));
        }
Exemple #7
0
        public WithIdleOverlay(Actor self, WithIdleOverlayInfo info)
        {
            var rs       = self.Trait <RenderSprites>();
            var body     = self.Trait <IBodyOrientation>();
            var disabled = self.TraitsImplementing <IDisable>();

            buildComplete = !self.HasTrait <Building>();            // always render instantly for units
            overlay       = new Animation(self.World, rs.GetImage(self));
            overlay.PlayRepeating(info.Sequence);
            rs.Add("idle_overlay_{0}".F(info.Sequence),
                   new AnimationWithOffset(overlay,
                                           () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
                                           () => !buildComplete,
                                           () => info.PauseOnLowPower && disabled.Any(d => d.Disabled),
                                           p => WithTurret.ZOffsetFromCenter(self, p, 1)),
                   info.Palette, info.IsPlayerPalette);
        }
Exemple #8
0
        public WithBarrel(Actor self, WithBarrelInfo info)
        {
            this.self = self;
            this.info = info;
            body      = self.Trait <IBodyOrientation>();
            armament  = self.TraitsImplementing <Armament>()
                        .First(a => a.Info.Name == info.Armament);
            turreted = self.TraitsImplementing <Turreted>()
                       .First(tt => tt.Name == armament.Info.Turret);

            var rs = self.Trait <RenderSprites>();

            anim = new Animation(self.World, rs.GetImage(self), () => turreted.TurretFacing);
            anim.Play(info.Sequence);
            rs.Add("barrel_{0}".F(info.Barrel), new AnimationWithOffset(
                       anim, () => BarrelOffset(), null, () => false, p => WithTurret.ZOffsetFromCenter(self, p, 0)));

            // Restrict turret facings to match the sprite
            turreted.QuantizedFacings = anim.CurrentSequence.Facings;
        }