public static Effect ParseEffect(XElement node)
        {
            Effect action = entity => { };

            foreach (XElement prop in node.Elements())
            {
                switch (prop.Name.LocalName)
                {
                case "Name":
                    string spritename = prop.Value;

                    action += entity =>
                    {
                        SpriteComponent spritecomp = entity.GetComponent <SpriteComponent>();
                        spritecomp.ChangeSprite(spritename);
                    };
                    break;

                case "Playing":
                    bool play = prop.GetValue <bool>();
                    action += entity =>
                    {
                        SpriteComponent spritecomp = entity.GetComponent <SpriteComponent>();
                        spritecomp.Playing = play;
                    };
                    break;

                case "Visible":
                    bool vis = prop.GetValue <bool>();
                    action += entity =>
                    {
                        SpriteComponent spritecomp = entity.GetComponent <SpriteComponent>();
                        spritecomp.Visible = vis;
                    };
                    break;

                case "Palette":
                    string pal   = prop.RequireAttribute("name").Value;
                    int    index = prop.GetAttribute <int>("index");
                    action += entity =>
                    {
                        var palette = PaletteSystem.Get(pal);
                        if (palette != null)
                        {
                            palette.CurrentIndex = index;
                        }
                    };
                    break;
                }
            }
            return(action);
        }
        protected override void Update()
        {
            Hit = false;

            if (flashing > 0)
            {
                flashing--;
                SpriteComponent spr = Parent.GetComponent <SpriteComponent>();
                if (spr != null)
                {
                    spr.Visible = (flashing % 3 != 1);
                }
            }
        }
        private void ApplyCurrent()
        {
            if (weapons[current].Palette.HasValue)
            {
                SpriteComponent sprites = Parent.GetComponent <SpriteComponent>();
                if (sprites != null)
                {
                    sprites.ChangePalette(weapons[current].Palette.Value);
                }
            }

            if (weapons[current].Meter != null)
            {
                weapons[current].Meter.Start(_container);
            }
        }
        public override Component Clone()
        {
            SpriteComponent copy = new SpriteComponent();

            foreach (var group in _sprites)
            {
                foreach (var spr in group.Value.NamedSprites)
                {
                    var copySprite = new Sprite(spr.Value);
                    copy.Add(group.Key, copySprite, spr.Key);
                }
            }

            copy.verticalFlip = verticalFlip;

            return(copy);
        }
        protected override void Update()
        {
            if (clearHitNextFrame)
            {
                Hit = false;
            }
            else
            {
                clearHitNextFrame = true;
            }

            if (flashing > 0)
            {
                flashing--;
                SpriteComponent spr = Parent.GetComponent <SpriteComponent>();
                if (spr != null)
                {
                    spr.Visible = (flashing % 3 != 1);
                }
            }
        }
 public SpriteGroup(SpriteComponent parent)
 {
     _parent = parent;
 }
        protected override void Update()
        {
            if (!CanMove || Parent.Paused)
            {
                return;
            }

            float accelX = (pendingVx - vx) * dragX;

            vx += accelX;

            float accelY = (pendingVy - vy) * dragY;

            vy += accelY;

            if (!Floating)
            {
                float gmult = (overTile != null) ? overTile.Properties.GravityMult : 1;

                if (Parent.Container.IsGravityFlipped)
                {
                    vy -= Parent.Container.Gravity * gmult;
                    if (vy < -Const.TerminalVel)
                    {
                        vy = -Const.TerminalVel;
                    }
                }
                else
                {
                    vy += Parent.Container.Gravity * gmult;
                    if (vy > Const.TerminalVel)
                    {
                        vy = Const.TerminalVel;
                    }
                }
            }

            if (FlipSprite)
            {
                SpriteComponent sprite = Parent.GetComponent <SpriteComponent>();
                if (sprite != null)
                {
                    sprite.HorizontalFlip = (Direction == Direction.Left);
                }
            }

            Tile nextOverTile = null;

            if (position != null)
            {
                float deltaX = vx + pushX;
                float deltaY = vy + pushY;

                PointF pos = position.Position;
                if (collision == null)
                {
                    pos.X += deltaX;
                    pos.Y += deltaY;
                }
                else
                {
                    if ((!collision.BlockLeft && deltaX < 0) || (!collision.BlockRight && deltaX > 0))
                    {
                        pos.X += deltaX;
                    }
                    if ((!collision.BlockTop && deltaY < 0) || (!collision.BlockBottom && deltaY > 0))
                    {
                        pos.Y += deltaY;
                    }
                }
                position.SetPosition(pos);

                nextOverTile = Parent.Screen.TileAt(position.Position.X, position.Position.Y);
            }

            if (Parent.Name == "Player")
            {
                if (overTile != null && nextOverTile != null && nextOverTile.Properties.Name != overTile.Properties.Name)
                {
                    if (overTile.Properties.OnLeave != null)
                    {
                        EffectParser.GetLateBoundEffect(overTile.Properties.OnLeave)(Parent);
                    }
                    if (nextOverTile.Properties.OnEnter != null)
                    {
                        EffectParser.GetLateBoundEffect(nextOverTile.Properties.OnEnter)(Parent);
                    }
                }

                if (nextOverTile != null && nextOverTile.Properties.OnOver != null)
                {
                    EffectParser.GetLateBoundEffect(nextOverTile.Properties.OnOver)(Parent);
                }
            }

            vx     *= resistX;
            vy     *= resistY;
            resistX = resistY = 1;

            pendingVx = vx;
            pendingVy = vy;

            overTile = nextOverTile;
            pushX    = pushY = 0;
            dragX    = dragY = 1;
        }