Пример #1
0
        /// <summary>
        /// Initializes the fighter controller
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            // Init engine trails
            this.trails = new List <TrailSetting>();
            for (int i = 0; i < this.trailPositions.Count; i++)
            {
                var         trailPosition = this.trailPositions[i];
                Transform3D trailTransform;

                Entity trailEntity = new Entity("trail_" + i)
                                     .AddComponent(trailTransform = new Transform3D()
                {
                    LocalPosition = trailPosition
                });

                this.Owner.AddChild(trailEntity);

                TrailSetting trail = this.trailManager.GetFreeTrail(trailTransform);

                trail.Thickness      = 1;
                trail.ExpirationTime = 1f;
                trail.TimeStep       = 0.02;
            }

            // Register fighter in screenplay manager
            var screenplay = this.EntityManager.Find("ScreenplayManager").FindComponent <ScreenplayManager>();

            screenplay.RegisterFighter(new FighterSetting()
            {
                State     = this.state,
                Transform = transform3D
            });


            // Gets all fighter guns
            this.guns = new List <ProjectileEmitter>();
            var gunEntities = this.Owner.ChildEntities.Where(e => e.Tag == "Gun");

            foreach (var gunEntity in gunEntities)
            {
                var projectileEmitter = gunEntity.FindComponent <ProjectileEmitter>();
                this.guns.Add(projectileEmitter);

                projectileEmitter.OnShoot += projectileEmitter_OnShoot;
            }

            this.laserTrigger.OnActionChange += laserTrigger_OnActionChange;


            // Load sound emitters
            var engineSoundEntity = this.Owner.FindChild("engineSoundEmitter");

            if (engineSoundEntity == null)
            {
                engineSoundEntity = this.Owner;
            }

            this.engineSoundEmitter = engineSoundEntity.FindComponent <Sound3DEmitter>();

            var gunsSoundEntity = this.Owner.FindChild("gunsSoundEmitter");

            if (gunsSoundEntity == null)
            {
                gunsSoundEntity = this.Owner;
            }

            this.gunsSoundEmitter = gunsSoundEntity.FindComponent <Sound3DEmitter>();
        }
Пример #2
0
        /// <summary>
        /// Creates a new explosion decorator
        /// </summary>
        /// <param name="name">The entity name</param>
        /// <param name="frame">The explosion frame </param>
        public ExplosionDecorator(string name, int frame)
        {
            this.particleSystems = new List <ParticleSystem3D>();

            this.entity = new Entity(name)
                          .AddComponent(this.cachedTransform = new Transform3D())
            ;

            ParticleSystem3D particleSystem;
            var emitter1 = new Entity()
                           .AddComponent(new Transform3D())
                           .AddComponent(emitter        = new Sound3DEmitter())
                           .AddComponent(particleSystem = new ParticleSystem3D()
            {
                NumParticles        = 25,
                EmitRate            = 300000,
                MinLife             = TimeSpan.FromSeconds(1),
                MaxLife             = TimeSpan.FromSeconds(1.5),
                LocalVelocity       = Vector3.Zero,
                RandomVelocity      = Vector3.One * 0.7f,
                MinSize             = 20,
                MaxSize             = 25,
                MaxRotateSpeed      = 0.025f,
                MinRotateSpeed      = -0.055f,
                InitialAngle        = MathHelper.TwoPi,
                EndDeltaScale       = 2f,
                EmitterSize         = new Vector2(4),
                EmitterShape        = ParticleSystem3D.Shape.FillRectangle,
                InterpolationColors = new List <Color>()
                {
                    Color.White, Color.White, Color.Black
                },
                LinearColorEnabled = true,
                Gravity            = Vector3.Zero,
                Emit = false
            })
                           .AddComponent(new ParticleSystemRenderer3D())
                           .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Explosion/Explosion_1.png", DefaultLayers.Additive)
            {
                VertexColorEnabled = true
            }))
            ;

            this.particleSystems.Add(particleSystem);


            var emitter2 = new Entity()
                           .AddComponent(new Transform3D())
                           .AddComponent(particleSystem = new ParticleSystem3D()
            {
                NumParticles        = 4,
                EmitRate            = 300000,
                MinLife             = TimeSpan.FromSeconds(0.2),
                MaxLife             = TimeSpan.FromSeconds(0.3),
                LocalVelocity       = Vector3.Zero,
                RandomVelocity      = Vector3.One * 0.01f,
                MinSize             = 30,
                MaxSize             = 40,
                InitialAngle        = MathHelper.TwoPi,
                MaxRotateSpeed      = 0.1f,
                MinRotateSpeed      = -0.1f,
                EndDeltaScale       = 0.3f,
                EmitterSize         = new Vector2(1),
                EmitterShape        = ParticleSystem3D.Shape.FillRectangle,
                InterpolationColors = new List <Color>()
                {
                    Color.White, Color.Black
                },
                LinearColorEnabled = true,
                Gravity            = Vector3.Zero,
                Emit = false
            })
                           .AddComponent(new ParticleSystemRenderer3D())
                           .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Explosion/Explosion_3.png", DefaultLayers.Additive)
            {
                VertexColorEnabled = true
            }))
            ;

            this.particleSystems.Add(particleSystem);

            var emitter3 = new Entity()
                           .AddComponent(new Transform3D())
                           .AddComponent(particleSystem = new ParticleSystem3D()
            {
                NumParticles        = 60,
                EmitRate            = 300000,
                MinLife             = TimeSpan.FromSeconds(2),
                MaxLife             = TimeSpan.FromSeconds(2.4),
                LocalVelocity       = Vector3.Zero,
                RandomVelocity      = Vector3.One * 1f,
                MinSize             = 0.7f,
                MaxSize             = 0.7f,
                InitialAngle        = MathHelper.TwoPi,
                Gravity             = Vector3.Zero,
                EndDeltaScale       = 1,
                EmitterSize         = new Vector2(1),
                EmitterShape        = ParticleSystem3D.Shape.FillRectangle,
                InterpolationColors = new List <Color>()
                {
                    Color.White, Color.Black
                },
                LinearColorEnabled = true,
                Emit = false
            })
                           .AddComponent(new ParticleSystemRenderer3D())
                           .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Blaster.png", DefaultLayers.Additive)
            {
                VertexColorEnabled = true
            }))
            ;

            this.particleSystems.Add(particleSystem);

            var emitter4 = new Entity()
                           .AddComponent(new Transform3D())
                           .AddComponent(particleSystem = new ParticleSystem3D()
            {
                NumParticles        = 15,
                EmitRate            = 300000,
                MinLife             = TimeSpan.FromSeconds(1.5),
                MaxLife             = TimeSpan.FromSeconds(4),
                LocalVelocity       = Vector3.Zero,
                RandomVelocity      = Vector3.One * 0.2f,
                MinSize             = 15,
                MaxSize             = 20,
                MaxRotateSpeed      = 0.015f,
                MinRotateSpeed      = -0.015f,
                InitialAngle        = MathHelper.TwoPi,
                EndDeltaScale       = 2f,
                EmitterSize         = new Vector2(4),
                EmitterShape        = ParticleSystem3D.Shape.FillRectangle,
                AlphaEnabled        = true,
                InterpolationColors = new List <Color>()
                {
                    Color.White * 0.5f, Color.Black
                },

                LinearColorEnabled = true,

                Gravity = Vector3.Zero,
                Emit    = false
            })
                           .AddComponent(new ParticleSystemRenderer3D())
                           .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Explosion/Explosion_5.png", DefaultLayers.Alpha)
            {
                VertexColorEnabled = true
            }))
            ;

            this.particleSystems.Add(particleSystem);


            Entity shockwave = new Entity("shockwave")
                               .AddComponent(new Transform3D()
            {
                Rotation = new Vector3(0.3f, -0.2f, -0.4f)
            })
                               .AddComponent(new Model("Content/Models/Plane.FBX"))
                               .AddComponent(new ModelRenderer())
                               .AddComponent(this.shockwave = new ShockwaveBehavior())
                               .AddComponent(new MaterialsMap(new BasicMaterial("Content/Textures/Explosion/Explosion_4.png", DefaultLayers.Additive)))
            ;


            this.entity.AddChild(emitter1);
            this.entity.AddChild(emitter2);
            this.entity.AddChild(emitter3);
            this.entity.AddChild(emitter4);
            this.entity.AddChild(shockwave);

            this.entity.EntityInitialized += (s, e) =>
            {
                var screenplay = this.entity.Scene.EntityManager.Find("ScreenplayManager").FindComponent <ScreenplayManager>();
                screenplay.FrameEvent(frame, this.BayExplosion);
            };
        }