private Trigger ParseTrigger(XElement triggerNode)
        {
            try
            {
                string conditionString;
                if (triggerNode.Attribute("condition") != null)
                {
                    conditionString = triggerNode.RequireAttribute("condition").Value;
                }
                else
                {
                    conditionString = triggerNode.Element("Condition").Value;
                }

                Condition condition = EffectParser.ParseCondition(conditionString);

                Effect effect = EffectParser.LoadTriggerEffect(triggerNode.Element("Effect"));

                return(new Trigger {
                    Condition = condition, Effect = effect
                });
            }
            catch (Exception e)
            {
                throw new GameXmlException(triggerNode, "There was an error parsing a trigger. There may be a syntax error in your condition expression.\n\nThe error message was:\n\n\t" + e.Message);
            }
        }
        private void EffectCommand(SceneEffectCommandInfo command)
        {
            var entity = Entities.GetEntityById(command.EntityId);

            var effect = EffectParser.GetOrLoadEffect(command.GeneratedName, command.EffectNode);

            effect(entity);
        }
Beispiel #3
0
        private void LoadFile(string path, List <string> pathArgs = null)
        {
            var projectLoader = new GameLoader();

            this.FileReaderProvider = projectLoader.Load(path);
            project = FileReaderProvider.GetProjectReader().Load();

            BasePath = project.BaseDir;

            PixelsDown   = project.ScreenHeight;
            PixelsAcross = project.ScreenWidth;

            if (ScreenSizeChanged != null)
            {
                ScreenSizeChangedEventArgs args = new ScreenSizeChangedEventArgs(PixelsAcross, PixelsDown);
                ScreenSizeChanged(this, args);
            }

            if (project.MusicNSF != null)
            {
                Engine.Instance.SoundSystem.LoadMusicNSF(project.MusicNSF.Absolute);
            }
            if (project.EffectsNSF != null)
            {
                Engine.Instance.SoundSystem.LoadSfxNSF(project.EffectsNSF.Absolute);
            }

            foreach (var stageInfo in project.Stages)
            {
                stageFactory.Load(stageInfo);
            }

            _tileProperties.LoadProperties(project.EntityProperties);
            _entitySource.LoadEntities(project.Entities);
            EffectParser.LoadEffectsList(project.Functions);
            Engine.Instance.SoundSystem.LoadEffectsFromInfo(project.Sounds);
            Scene.LoadScenes(project.Scenes);
            Menu.LoadMenus(project.Menus);
            FontSystem.Load(project.Fonts);
            PaletteSystem.LoadPalettes(project.Palettes);

            currentPath = path;

            if (pathArgs != null && pathArgs.Any())
            {
                ProcessCommandLineArgs(pathArgs);
            }
            else if (project.StartHandler != null)
            {
                _stateMachine.ProcessHandler(project.StartHandler);
            }
            else
            {
                throw new GameRunException("The game file loaded correctly, but it failed to specify a starting point!");
            }

            Player = new Player();
        }
        private void CallCommand(SceneCallCommandInfo command)
        {
            var player = Entities.GetEntityById("Player");

            if (player != null)
            {
                EffectParser.GetLateBoundEffect(command.Name)(player);
            }
        }
        private void ConditionCommand(SceneConditionCommandInfo command)
        {
            var condition = EffectParser.ParseCondition(command.ConditionExpression);
            var entity    = Entities.GetAll().FirstOrDefault(e => e.Name == command.ConditionEntity);

            if (condition(entity))
            {
                RunCommands(command.Commands);
            }
        }
Beispiel #6
0
        public static void LoadEffectsList(XElement element)
        {
            foreach (var effectnode in element.Elements("Function"))
            {
                string name = effectnode.RequireAttribute("name").Value;

                Effect effect = LoadEffect(effectnode);

                EffectParser.SaveEffect(name, effect);
            }
        }
Beispiel #7
0
        public static Effect LoadTriggerEffect(XElement effectnode)
        {
            Effect effect = LoadEffect(effectnode);

            // check for name to save
            XAttribute nameAttr = effectnode.Attribute("name");

            if (nameAttr != null)
            {
                EffectParser.SaveEffect(nameAttr.Value, effect);
            }
            return(effect);
        }
Beispiel #8
0
 public void Unload()
 {
     Engine.Instance.Stop();
     _stateMachine.StopAllHandlers();
     _entitySource.Unload();
     Engine.Instance.UnloadAudio();
     FontSystem.Unload();
     HealthMeter.Unload();
     Scene.Unload();
     Menu.Unload();
     PaletteSystem.Unload();
     EffectParser.Unload();
     CurrentGame = null;
 }
 private Trigger ParseTrigger(TriggerInfo info)
 {
     try
     {
         var condition  = EffectParser.ParseCondition(info.Condition);
         var effect     = EffectParser.LoadTriggerEffect(info.Effect);
         var elseEffect = (info.Else != null) ? EffectParser.LoadTriggerEffect(info.Else) : null;
         return(new Trigger {
             Condition = condition, Effect = effect, Else = elseEffect, ConditionString = info.Condition, Priority = info.Priority ?? 0
         });
     }
     catch (Exception e)
     {
         throw new GameRunException("There was an error parsing a trigger. There may be a syntax error in your condition expression.\n\nThe error message was:\n\n\t" + e.Message);
     }
 }
        internal void LoadInfo(StateComponentInfo componentInfo)
        {
            foreach (var stateInfo in componentInfo.States)
            {
                var state = new State()
                {
                    Name = stateInfo.Name
                };
                foreach (var trigger in stateInfo.Triggers)
                {
                    state.AddTrigger(ParseTrigger(trigger));
                }

                state.SetInitial(EffectParser.LoadTriggerEffect(stateInfo.Initializer));
                state.SetLogic(EffectParser.LoadTriggerEffect(stateInfo.Logic));

                states[state.Name] = state;
            }

            foreach (var triggerInfo in componentInfo.Triggers)
            {
                var trigger = ParseTrigger(triggerInfo.Trigger);

                if (triggerInfo.States != null)
                {
                    foreach (var stateName in triggerInfo.States)
                    {
                        if (!states.ContainsKey(stateName))
                        {
                            State state = new State {
                                Name = stateName
                            };
                            states.Add(stateName, state);
                        }
                        states[stateName].AddTrigger(trigger);
                    }
                }
                else
                {
                    foreach (var state in states.Values)
                    {
                        state.AddTrigger(trigger);
                    }
                }
            }
        }
        public override void LoadXml(XElement stateNode)
        {
            string name = stateNode.RequireAttribute("name").Value;

            State state;

            if (states.ContainsKey(name))
            {
                state = states[name];
            }
            else
            {
                state = new State {
                    Name = name
                };
                states[name] = state;
            }

            foreach (XElement child in stateNode.Elements())
            {
                switch (child.Name.LocalName)
                {
                case "Trigger":
                    state.AddTrigger(ParseTrigger(child));
                    break;

                default:
                    // make sure the entity has the component we're dealing with
                    // if it's not a component name it will just return null safely
                    Parent.GetOrCreateComponent(child.Name.LocalName);

                    if (child.Attribute("mode") != null && child.RequireAttribute("mode").Value.ToUpper() == "REPEAT")
                    {
                        state.AddLogic(EffectParser.LoadEffectAction(child));
                    }
                    else
                    {
                        state.AddInitial(EffectParser.LoadEffectAction(child));
                    }
                    break;
                }
            }
        }
Beispiel #12
0
        private void IncludeXmlFile(string path)
        {
            try
            {
                XDocument document = XDocument.Load(path, LoadOptions.SetLineInfo);
                foreach (XElement element in document.Elements())
                {
                    switch (element.Name.LocalName)
                    {
                    case "Entities":
                        _entitySource.LoadEntities(element);
                        _tileProperties.LoadProperties(element);
                        break;

                    case "Functions":
                        EffectParser.LoadEffectsList(element);
                        break;

                    case "Sounds":
                    case "Scenes":
                    case "Scene":
                    case "Menus":
                    case "Menu":
                    case "Fonts":
                    case "Palettes":
                        break;

                    default:
                        throw new GameXmlException(element, string.Format("Unrecognized XML type: \"{0}\"", element.Name.LocalName));
                    }
                }
            }
            catch (GameXmlException ex)
            {
                ex.File = path;
                throw;
            }
        }
        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;
        }