Ejemplo n.º 1
0
        public void Kill(Entity target, int delayMillis = 0)
        {
            Logger.Debug("Simulator", "Kill", "Trying to kill " + target.ID);
            target.Kill();
            if (target.Visible == true)
            {
                if (target.DeathAnimation == String.Empty)
                {
                    //CreateParticleAt (SPAWN_PARTICLE, target.X, target.Y);
                    var ps = new ParticleSystem("DEATH");
                    ps.TTL      = 2000;
                    ps.Layer    = this.world.worldView.ObjectsLayer;
                    ps.Position = new Vector2f(target.X * this.CellWidth + target.DeathRect.Left, target.Y * this.CellHeight + target.DeathRect.Top);

                    var emitter = new Emitter(ps, 0);
                    //emitter.Offset = new Vector2f (target.DeathRect.Top, target.DeathRect.Left);
                    emitter.ParticleTTL    = 800;
                    emitter.SpawnCount     = 64;
                    emitter.SpawnDeltaTime = 50;
                    emitter.StartDelay     = 250;
                    emitter.TTL            = 90;
                    emitter.AddParticleTemplate("00_base_pc_fx.png", 576, 0, 1, 1, 2);
                    emitter.AddParticleTemplate("00_base_pc_fx.png", 576, 0, 1, 1, 2);
                    emitter.AddParticleTemplate("00_base_pc_fx.png", 576, 0, 1, 1, 4);
                    emitter.AddAnimator(new GravityAnimation(new Vector2f(0f, 0.0002f)));
                    emitter.AddAnimator(new FadeAnimation(0, 0, 800));
                    emitter.AddVariator(new GridSpawner(target.DeathRect.Width, target.DeathRect.Height, 4, 4));
                    emitter.AddVariator(new BurstSpawner(0.05f));
                    var cps = new ColorPickerSpawner();
                    cps.AddColor(target.DeathMain);
                    cps.AddColor(target.DeathMain);
                    cps.AddColor(target.DeathSecundary);
                    emitter.AddVariator(cps);
                    ps.AddEmitter(emitter);

                    //var ps = GameFactory.LoadParticleFromTemplate (pid, target.X * this.CellWidth, target.Y * this.CellHeight, this.world.worldView.ObjectsLayer);
                    IoManager.AddWidget(ps);
                    target.OutObject.AddAnimator(new FadeAnimation(0, delayMillis, 500));
                }
                else
                {
                    SetAnimation(target, target.DeathAnimation);
                }
                this.events.WaitAndRun(delayMillis /* + 500*/, new DestroyEvent(target.ID));
            }
            else
            {
                this.DestroyObject(target.ID);
            }
        }
Ejemplo n.º 2
0
        static public ParticleSystem LoadParticleFromTemplate(string templateId, float x, float y, ObjectsLayer layer, bool flip = false)
        {
            try {
                var     res      = new ParticleSystem(templateId);
                XmlNode template = GameFactory.xdoc.SelectSingleNode("//particle[@id='" + templateId + "']");
                if (XmlUtilities.GetString(template, "flip", "true") == "false")
                {
                    flip = false;
                }
                var xCoeff     = flip ? -1f : 1f;
                var angleCoeff = flip ? 3.1415f : 0f;
                res.TTL = XmlUtilities.GetInt(template, "ttl");
                if (res.TTL < 0)
                {
                    res.TTL = int.MaxValue;
                }
                res.Layer    = layer;
                res.Position = new Vector2f(x, y);

                var emitters = template.SelectNodes("./emitter");
                for (int e = 0; e < emitters.Count; e++)
                {
                    Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New emitter: " + emitters [e].ToString());
                    var startDelay = XmlUtilities.GetInt(emitters [e], "startDelay");
                    var emitter    = new Emitter(res, startDelay);
                    emitter.Offset = new Vector2f(
                        XmlUtilities.GetFloat(emitters [e], "offsetX") * xCoeff,
                        XmlUtilities.GetFloat(emitters [e], "offsetY")
                        );
                    emitter.ParticleTTL    = XmlUtilities.GetInt(emitters [e], "particleTtl");
                    emitter.SpawnCount     = XmlUtilities.GetInt(emitters [e], "spawnCount");
                    emitter.SpawnDeltaTime = XmlUtilities.GetInt(emitters [e], "spawnDeltaTime");
                    emitter.TTL            = XmlUtilities.GetInt(emitters [e], "ttl");
                    if (emitter.TTL < 0)
                    {
                        emitter.TTL = int.MaxValue;
                    }
                    emitter.ZIndex = XmlUtilities.GetInt(emitters [e], "zIndex", 0);

                    var children = emitters [e].ChildNodes;
                    for (var c = 0; c < children.Count; c++)
                    {
                        switch (children [c].Name)
                        {
                        case "boxSpawner":
                            emitter.AddVariator(new BoxSpawner(
                                                    XmlUtilities.GetFloat(children [c], "width"),
                                                    XmlUtilities.GetFloat(children [c], "height")
                                                    ));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New BoxSpawner: " + children [c].ToString());
                            break;

                        case "burstSpawner":
                            emitter.AddVariator(new BurstSpawner(
                                                    XmlUtilities.GetFloat(children [c], "maxForce"),
                                                    XmlUtilities.GetFloat(children [c], "minForce"),
                                                    XmlUtilities.GetFloat(children [c], "maxAngle") + angleCoeff,
                                                    XmlUtilities.GetFloat(children [c], "minAngle") + angleCoeff
                                                    ));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New BurstSpawner: " + children [c].ToString());
                            break;

                        case "burstInSpawner":
                            emitter.AddVariator(new BurstInSpawner(
                                                    XmlUtilities.GetFloat(children [c], "maxRadius"),
                                                    XmlUtilities.GetFloat(children [c], "minRadius"),
                                                    XmlUtilities.GetFloat(children [c], "maxForce"),
                                                    XmlUtilities.GetFloat(children [c], "minForce"),
                                                    XmlUtilities.GetFloat(children [c], "maxAngle") + angleCoeff,
                                                    XmlUtilities.GetFloat(children [c], "minAngle") + angleCoeff
                                                    ));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New BurstInSpawner: " + children [c].ToString());
                            break;

                        case "colorAnimation":
                            var buff       = XmlUtilities.GetIntArray(children [c], "startColor");
                            var startColor = new Color((byte)buff [0], (byte)buff [1], (byte)buff [2]);
                            if (buff.Length > 3)
                            {
                                startColor.A = (byte)buff [3];
                            }
                            buff = XmlUtilities.GetIntArray(children [c], "endColor");
                            var endColor = new Color((byte)buff [0], (byte)buff [1], (byte)buff [2]);
                            if (buff.Length > 3)
                            {
                                endColor.A = (byte)buff [3];
                            }
                            emitter.AddAnimator(new ColorAnimation(startColor, endColor, XmlUtilities.GetInt(children [c], "duration")));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New ColorAnimator: " + children [c].ToString());
                            break;

                        case "colorPicker":
                            var cps    = new ColorPickerSpawner();
                            var colors = children [c].SelectNodes("./color");
                            for (int i = 0; i < colors.Count; i++)
                            {
                                var color = XmlUtilities.GetIntArray(colors [i], "select");
                                switch (color.Length)
                                {
                                case 3:
                                    cps.AddColor(new Color((byte)color [0], (byte)color [1], (byte)color [2]));
                                    break;

                                case 4:
                                    cps.AddColor(new Color((byte)color [0], (byte)color [1], (byte)color [2], (byte)color [3]));
                                    break;

                                default:
                                    break;
                                }
                            }
                            emitter.AddVariator(cps);
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New ColorPickerSpawner: " + children [c].ToString());
                            break;

                        case "fade":
                            emitter.AddAnimator(new FadeAnimation(
                                                    XmlUtilities.GetInt(children [c], "fadeInDuration"),
                                                    XmlUtilities.GetInt(children [c], "duration"),
                                                    XmlUtilities.GetInt(children [c], "fadeOutDuration")
                                                    ));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New FadeAnimator: " + children [c].ToString());
                            break;

                        case "gravity":
                            emitter.AddAnimator(new GravityAnimation(new Vector2f(
                                                                         XmlUtilities.GetFloat(children [c], "forceX") * xCoeff,
                                                                         XmlUtilities.GetFloat(children [c], "forceY")
                                                                         )));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New GravityAnimation: " + children [c].ToString());
                            break;

                        case "gridSpawner":
                            emitter.AddVariator(new GridSpawner(
                                                    XmlUtilities.GetInt(children [c], "gridWidth"),
                                                    XmlUtilities.GetInt(children [c], "gridHeight"),
                                                    XmlUtilities.GetFloat(children [c], "cellWidth") * xCoeff,
                                                    XmlUtilities.GetFloat(children [c], "cellHeight"),
                                                    XmlUtilities.GetFloat(children [c], "deltaX", 0f),
                                                    XmlUtilities.GetFloat(children [c], "deltaY", 0f)
                                                    ));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New GridSpawner: " + children [c].ToString());
                            break;

                        case "lightSpawner":
                            buff = XmlUtilities.GetIntArray(children [c], "color");
                            var lightColor = new Color((byte)buff [0], (byte)buff [1], (byte)buff [2]);
                            if (buff.Length > 3)
                            {
                                lightColor.A = (byte)buff [3];
                            }
                            emitter.AddVariator(new LightSpawner(lightColor, XmlUtilities.GetInt(children [c], "radius")));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New LightSpawner: " + children [c].ToString());
                            break;

                        case "particleTemplate":
                            if (children [c].HasChildNodes)
                            {
                                emitter.AddParticleTemplate(
                                    XmlUtilities.GetString(children [c], "texture"),
                                    XmlUtilities.GetInt(children [c], "x"),
                                    XmlUtilities.GetInt(children [c], "y"),
                                    XmlUtilities.GetInt(children [c], "width"),
                                    XmlUtilities.GetInt(children [c], "height"),
                                    XmlUtilities.GetFloat(children [c], "scale", 1f),
                                    LoadAnimationDefinition(children [c])
                                    );
                            }
                            else
                            {
                                emitter.AddParticleTemplate(
                                    XmlUtilities.GetString(children [c], "texture"),
                                    XmlUtilities.GetInt(children [c], "x"),
                                    XmlUtilities.GetInt(children [c], "y"),
                                    XmlUtilities.GetInt(children [c], "width"),
                                    XmlUtilities.GetInt(children [c], "height"),
                                    XmlUtilities.GetFloat(children [c], "scale", 1f)
                                    );
                            }
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New particle: " + children [c].ToString());
                            break;

                        case "scaleAnimation":
                            emitter.AddAnimator(new ScaleAnimation(
                                                    XmlUtilities.GetInt(children [c], "duration"),
                                                    XmlUtilities.GetFloat(children [c], "start"),
                                                    XmlUtilities.GetFloat(children [c], "end")
                                                    ));
                            break;

                        case "sfxSpawner":
                            emitter.AddVariator(new SfxSpawner(
                                                    XmlUtilities.GetString(children [c], "sfx")
                                                    ));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New SfxSpawner: " + children [c].ToString());
                            break;

                        case "zAnimation":
                            emitter.AddAnimator(new ZAnimation(
                                                    XmlUtilities.GetInt(children [c], "duration"),
                                                    XmlUtilities.GetInt(children [c], "start"),
                                                    XmlUtilities.GetInt(children [c], "end")
                                                    ));
                            Logger.Debug("GameFactory", "LoadParticleFromTemplate", "New ZAnimation: " + children [c].ToString());
                            break;

                        default:
                            break;
                        }
                    }

                    res.AddEmitter(emitter);
                }

                Logger.Debug("GameFactory", "LoadParticleFromTemplate", "Built particle system " + templateId);

                return(res);
            }
            catch (Exception ex) {
                Logger.Warning("GameFactory", "LoadParticleFromTemplate", ex.ToString());
                return(null);
            }
        }