Example #1
0
 protected override void OnInitialize()
 {
     base.OnInitialize();
     MovementComponent = this.GetDependency<MovementComponent>();
     PathComponent = this.GetDependency<PathComponent>();
     MovementComponent = this.GetDependency<MovementComponent>();
     CombatComponent = this.GetDependency<CombatComponent>();
     PhysicsSystem = Parent.Scene.GetSystem<PhysicsSystem>();
     PhysicsComponent = this.GetDependency<PhysicsComponent>();
     AttributesComponent = this.GetDependency<AttributesComponent>();
     SpriteComponent = this.GetDependency<SpriteComponent>();
     HealthBarComponent = this.GetDependency<HealthBarComponent>();
     DamageComponent = this.GetDependency<DamageComponent>();
 }
Example #2
0
        private static List<Entity> ParseEntities(MapDetails Map)
        {
            List<Entity> Entities = new List<Entity>();
            List<PathDetails> Paths = new List<PathDetails>();
            foreach(XmlNode ObjectGroupNode in Map.MapElement.SelectNodes("objectgroup")) {
                foreach(XmlNode ObjectNode in ObjectGroupNode.SelectNodes("object")) {
                    ObjectType Type = ReadObjectType(ObjectNode);
                    if(Type == ObjectType.Path) {
                        var Path = ParsePath(ObjectNode);
                        Paths.Add(Path);
                    } else if(Type == ObjectType.Entity) {
                        var Entity = ParseEntity(ObjectNode);
                        Entities.Add(Entity);
                    } else
                        throw new ArgumentException("Unknown object type '" + Type + "'.");
                }
            }

            foreach(var Path in Paths) {
                var Entity = Entities.Where(c => c.Name.Equals(Path.EntityName, StringComparison.InvariantCultureIgnoreCase));
                foreach (var e in Entity)
                {
                    var PathComponent = e.GetComponent<PathComponent>();
                    if (PathComponent == null)
                    {
                        PathComponent = new PathComponent();
                        e.Components.Add(PathComponent);
                    }
                    if (PathComponent.Nodes != null)
                        PathComponent.Nodes.Clear();
                    foreach (var Node in Path.Nodes)
                        PathComponent.AddNode(Node);
                }
            }
            return Entities;
        }