Example #1
0
        public Effect Load(IEffectPartInfo info)
        {
            var delayInfo = (DelayedEffectPartInfo)info;
            var frames    = delayInfo.DelayFrames;
            var effect    = EffectParser.LoadTriggerEffect(delayInfo.Effect);

            return(e =>
            {
                Engine.Instance.DelayedCall(() => effect(e), null, frames);
            });
        }
Example #2
0
        public Effect Load(IEffectPartInfo info)
        {
            var triggerInfo = (TriggerEffectPartInfo)info;

            Condition condition     = EffectParser.ParseCondition(triggerInfo.Trigger.Condition);
            Effect    triggerEffect = EffectParser.LoadTriggerEffect(triggerInfo.Trigger.Effect);
            Effect    elseEffect    = (triggerInfo.Trigger.Else != null) ? EffectParser.LoadTriggerEffect(triggerInfo.Trigger.Else) : null;

            return(e =>
            {
                if (condition(e))
                {
                    triggerEffect(e);
                }
                else if (elseEffect != null)
                {
                    elseEffect(e);
                }
            });
        }
Example #3
0
        private void LoadEntity(XElement xml)
        {
            GameEntity entity = new GameEntity();
            string     name   = xml.RequireAttribute("name").Value;

            if (entities.ContainsKey(name))
            {
                throw new GameXmlException(xml, "You have defined two entities both named \"" + name + "\".");
            }

            entity.Name     = name;
            entity.MaxAlive = xml.TryAttribute <int>("limit", 50);

            SpriteComponent   spritecomp = null;
            PositionComponent poscomp    = null;
            StateComponent    statecomp  = new StateComponent();

            entity.AddComponent(statecomp);

            try
            {
                foreach (XElement xmlComp in xml.Elements())
                {
                    switch (xmlComp.Name.LocalName)
                    {
                    case "EditorData":
                        break;

                    case "Tilesheet":
                        if (spritecomp == null)
                        {
                            spritecomp = new SpriteComponent();
                            entity.AddComponent(spritecomp);
                        }
                        if (poscomp == null)
                        {
                            poscomp = new PositionComponent();
                            entity.AddComponent(poscomp);
                        }
                        spritecomp.LoadTilesheet(xmlComp);
                        break;

                    case "Trigger":
                        statecomp.LoadStateTrigger(xmlComp);
                        break;

                    case "Sprite":
                        if (spritecomp == null)
                        {
                            spritecomp = new SpriteComponent();
                            entity.AddComponent(spritecomp);
                        }
                        if (poscomp == null)
                        {
                            poscomp = new PositionComponent();
                            entity.AddComponent(poscomp);
                        }
                        spritecomp.LoadXml(xmlComp);
                        break;

                    case "Position":
                        if (poscomp == null)
                        {
                            poscomp = new PositionComponent();
                            entity.AddComponent(poscomp);
                        }
                        poscomp.LoadXml(xmlComp);
                        break;

                    case "Death":
                        entity.OnDeath += EffectParser.LoadTriggerEffect(xmlComp);
                        break;

                    case "GravityFlip":
                        entity.IsGravitySensitive = xmlComp.GetValue <bool>();
                        break;

                    default:
                        entity.GetOrCreateComponent(xmlComp.Name.LocalName).LoadXml(xmlComp);
                        break;
                    }
                }
            }
            catch (GameXmlException ex)
            {
                ex.Entity = name;
                throw;
            }

            entities.Add(name, entity);
        }
Example #4
0
        private void LoadEntity(EntityInfo info)
        {
            if (entities.ContainsKey(info.Name))
            {
                throw new GameEntityException("You have defined two entities both named \"" + info.Name + "\".");
            }

            var entity = new GameEntity();

            entity.Name = info.Name;

            entities[info.Name] = entity;

            entity.IsGravitySensitive = info.GravityFlip;

            if (info.Death != null)
            {
                entity.OnDeath = EffectParser.LoadTriggerEffect(info.Death);
            }

            if (info.SpriteComponent != null)
            {
                LoadSpriteComponent(entity, info.SpriteComponent);
            }

            if (info.PositionComponent != null || info.SpriteComponent != null)
            {
                LoadPositionComponent(entity, info.PositionComponent);
            }

            if (info.MovementComponent != null)
            {
                LoadMovementComponent(info.MovementComponent, entity);
            }

            if (info.InputComponent != null)
            {
                entity.AddComponent(new InputComponent());
            }

            if (info.CollisionComponent != null)
            {
                LoadCollisionComponent(entity, info.CollisionComponent);
            }

            if (info.StateComponent != null)
            {
                LoadStateComponent(entity, info.StateComponent);
            }

            if (info.HealthComponent != null)
            {
                LoadHealthComponent(entity, info.HealthComponent);
            }

            if (info.WeaponComponent != null)
            {
                LoadWeaponComponent(entity, info.WeaponComponent);
            }

            if (info.LadderComponent != null)
            {
                LoadLadderComponent(entity, info.LadderComponent);
            }

            // everyone gets these
            entity.AddComponent(new SoundComponent());
            entity.AddComponent(new TimerComponent());
            entity.AddComponent(new VarsComponent());
        }