Ejemplo n.º 1
0
        public override Entity Create(Main main)
        {
            Entity result = new Entity(main, "Blast");

            Transform transform = new Transform();
            result.Add("Transform", transform);

            PhysicsBlock physics = new PhysicsBlock();
            result.Add("Physics", physics);

            Model model = new Model();
            result.Add("Model", model);
            model.Filename.Value = "Models\\blast";
            model.Color.Value = new Vector3(0.75f, 2.0f, 0.75f);

            PointLight light = new PointLight();
            light.Shadowed.Value = true;
            light.Color.Value = new Vector3(model.Color.Value.X, model.Color.Value.Y, model.Color.Value.Z);
            light.Attenuation.Value = 10.0f;
            result.Add("Light", light);

            if (ParticleSystem.Get(main, "Sparks") == null)
            {
                ParticleSystem.Add(main, "Sparks",
                new ParticleSystem.ParticleSettings
                {
                    TextureName = "Particles\\spark",
                    MaxParticles = 1000,
                    Duration = TimeSpan.FromSeconds(1.0f),
                    MinHorizontalVelocity = 0.0f,
                    MaxHorizontalVelocity = 0.0f,
                    MinVerticalVelocity = 0.0f,
                    MaxVerticalVelocity = 0.0f,
                    Gravity = new Vector3(0.0f, 0.0f, 0.0f),
                    EndVelocity = 0.0f,
                    MinRotateSpeed = -20.0f,
                    MaxRotateSpeed = 20.0f,
                    MinStartSize = 0.5f,
                    MaxStartSize = 0.4f,
                    MinEndSize = 0.2f,
                    MaxEndSize = 0.1f,
                    BlendState = Microsoft.Xna.Framework.Graphics.BlendState.Additive,
                    MinColor = new Vector4(0.75f, 2.0f, 0.75f, 1.0f),
                    MaxColor = new Vector4(0.75f, 2.0f, 0.75f, 1.0f),
                });
            }

            ParticleEmitter emitter = new ParticleEmitter();
            emitter.ParticleType.Value = "Sparks";
            emitter.ParticlesPerSecond.Value = 200;
            emitter.Jitter.Value = new Vector3(0.25f);
            result.Add("Particles", emitter);

            Sound loopSound = new Sound();
            result.Add("LoopSound", loopSound);
            loopSound.Cue.Value = "Blast Loop";

            return result;
        }
Ejemplo n.º 2
0
        public override void Bind(Entity result, Main main, bool creating = false)
        {
            Factory.Get<DynamicMapFactory>().Bind(result, main, creating);

            Transform transform = result.Get<Transform>();
            DynamicMap map = result.Get<DynamicMap>();

            Sound zombieSound = new Sound();
            zombieSound.Serialize = false;
            zombieSound.Cue.Value = "Zombie";
            result.Add("ZombieSound", zombieSound);

            Property<bool> playerVisible = new Property<bool> { Value = false, Editable = false, Serialize = false };
            result.Add("PlayerVisible", playerVisible);

            zombieSound.Add(new Binding<Vector3>(zombieSound.Position, transform.Position));
            zombieSound.Add(new Binding<Vector3>(zombieSound.Velocity, map.LinearVelocity));

            Property<float> damage = result.GetProperty<float>("Damage");

            map.Add(new CommandBinding<Collidable, ContactCollection>(map.Collided, delegate(Collidable collidable, ContactCollection contact)
            {
                if (result.Active && collidable is EntityCollidable)
                {
                    if (((EntityCollidable)collidable).Entity.Tag is Player)
                    {
                        Player player = (Player)((EntityCollidable)collidable).Entity.Tag;
                        player.Health.Value -= damage;
                    }
                }
            }));

            Property<float> zombieSoundPitch = zombieSound.GetProperty("Pitch");

            Property<float> visibilityCheckInterval = result.GetProperty<float>("VisibilityCheckInterval");
            Property<float> torqueMultiplier = result.GetProperty<float>("TorqueMultiplier");
            Property<float> maxSpeed = result.GetProperty<float>("MaxSpeed");
            Property<float> playerPositionMemoryTime = result.GetProperty<float>("PlayerPositionMemoryTime");

            float timeSinceLastSpottedPlayer = playerPositionMemoryTime;
            float timeSinceLastVisibilityCheck = 0.0f;

            result.Add(new Updater
            {
                delegate(float dt)
                {
                    if (!result.Active)
                        return;

                    Entity player = PlayerFactory.Instance;
                    if (player != null)
                    {
                        Vector3 playerPosition = player.Get<Transform>().Position.Value;

                        Vector3 rayDirection = playerPosition - transform.Position;

                        float playerDistance = rayDirection.Length();

                        rayDirection /= playerDistance;

                        timeSinceLastVisibilityCheck += dt;
                        if (timeSinceLastVisibilityCheck > visibilityCheckInterval)
                        {
                            Map.GlobalRaycastResult hit = Map.GlobalRaycast(playerPosition + (rayDirection * -3.0f), -rayDirection, playerDistance);
                            if (hit.Map == map)
                            {
                                timeSinceLastSpottedPlayer = 0.0f;
                                playerVisible.Value = true;
                            }
                            timeSinceLastVisibilityCheck = 0.0f;
                        }
                        timeSinceLastSpottedPlayer += dt;

                        if (timeSinceLastSpottedPlayer < playerPositionMemoryTime)
                        {
                            float torque = torqueMultiplier * map.PhysicsEntity.Mass * dt;
                            Vector3 impulse = new Vector3(torque * rayDirection.Z, 0.0f, -torque * rayDirection.X);
                            map.PhysicsEntity.ApplyAngularImpulse(ref impulse);
                            Vector3 velocity = map.PhysicsEntity.AngularVelocity;
                            float speed = velocity.Length();
                            if (speed > maxSpeed)
                                map.PhysicsEntity.AngularVelocity = velocity * (maxSpeed / speed);

                            map.PhysicsEntity.ActivityInformation.Activate();
                            zombieSoundPitch.Value = ((speed / maxSpeed) / torque) - 1.0f;
                        }
                        else if (playerVisible)
                            playerVisible.Value = false;
                    }

                    if (timeSinceLastSpottedPlayer > playerPositionMemoryTime && zombieSound.IsPlaying)
                        zombieSound.Stop.Execute(Microsoft.Xna.Framework.Audio.AudioStopOptions.AsAuthored);
                    else if (timeSinceLastSpottedPlayer < playerPositionMemoryTime && !zombieSound.IsPlaying)
                        zombieSound.Play.Execute();
                }
            });
        }
Ejemplo n.º 3
0
        public override Entity Create(Main main)
        {
            Entity result = Factory.Get<DynamicMapFactory>().Create(main);
            result.Type = "Turret";

            PointLight light = new PointLight();
            light.Shadowed.Value = true;
            light.Color.Value = new Vector3(0.75f, 2.0f, 0.75f);
            light.Attenuation.Value = 0.0f;
            light.Editable = false;
            result.Add("Light", light);

            Sound blastChargeSound = new Sound();
            blastChargeSound.Cue.Value = "Blast Charge";
            result.Add("BlastChargeSound", blastChargeSound);

            Sound blastFireSound = new Sound();
            blastFireSound.Cue.Value = "Blast Fire";
            result.Add("BlastFireSound", blastFireSound);

            result.Add("Damage", new Property<float> { Editable = true, Value = 0.1f });
            result.Add("VisibilityCheckInterval", new Property<float> { Editable = true, Value = 1.0f });
            result.Add("BlastChargeTime", new Property<float> { Editable = true, Value = 1.25f });
            result.Add("BlastInterval", new Property<float> { Editable = true, Value = 1.0f });
            result.Add("PlayerPositionMemoryTime", new Property<float> { Editable = true, Value = 4.0f });
            result.Add("BlastSpeed", new Property<float> { Editable = true, Value = 75.0f });
            result.Add("PlayerDetectionRadius", new Property<float> { Editable = true, Value = 15.0f });

            return result;
        }