Exemplo n.º 1
0
        public void Initialize()
        {
            var placedTiles = new HashSet <TilePos>(_layout.GetObjects("Trap").Select(x => x.Position));

            foreach (var node in _layout.Nodes.Values)
            {
                if (!placedTiles.Contains(node.Position))
                {
                    WorldObjects.Empty.Do(CreateEntity(node.Position), _pool);
                }
            }

            var objectCreator = new List <TypeToEntityPerformer>()
            {
                new TypeToEntityPerformer("Player", WorldObjects.Hero),
                new TypeToEntityPerformer("Boss", WorldObjects.Boss),
                new TypeToEntityPerformer("Trap", WorldObjects.SpikeTrap),
                new TypeToEntityPerformer("TrapItem", WorldObjects.Spikes),
                new TypeToEntityPerformer("MoveableBlocker", WorldObjects.Box)
            };

            foreach (var creator in objectCreator)
            {
                var puzzleObjects = _layout.GetObjects(creator.Type);
                foreach (var puzzleObject in puzzleObjects)
                {
                    var entity = creator.EntityPerformer.Do(CreateEntity(puzzleObject.Position), _pool);
                    if (puzzleObject.Properties.ContainsKey("Health"))
                    {
                        entity.ReplaceHealth((int)puzzleObject.Properties["Health"].Value);
                    }
                    if (puzzleObject.Properties.ContainsKey("IsLoaded") && (bool)puzzleObject.Properties["IsLoaded"].Value)
                    {
                        entity.ReplaceLoaded(true);
                    }
                }
            }

            _pool.CreateEntity().AddResource("Camera").AddRotation(0).ReplaceTargetFocusPoint(Vector3.zero);

            _pool.isLevelLoaded = true;
        }