Exemplo n.º 1
0
        /// <summary>
        /// Adds the cells from prefab to the level builder.
        /// </summary>
        /// <param name="builder">The level builder.</param>
        /// <param name="upperLeft">The upper left position of the prefab within the level.</param>
        /// <param name="flipX">if set to <c>true</c> the prefab will be flipped horizontally.</param>
        /// <param name="flipY">if set to <c>true</c> the prefab will be flipped vertically.</param>
        /// <param name="prefabGuid">The prefab instance's unique identifier.</param>
        /// <param name="prefab">The prefab.</param>
        /// <param name="prefabDimensions">The prefab dimensions.</param>
        private static void AddCellsFromPrefab(LevelBuilder builder,
                                               Pos2D upperLeft,
                                               bool flipX,
                                               bool flipY,
                                               Guid prefabGuid,
                                               PrefabData prefab,
                                               Pos2D prefabDimensions)
        {
            // Loop over the rows in the prefab
            int y = 0;

            foreach (var row in prefab.Data)
            {
                // Loop over the cells in the prefab
                int x = 0;
                foreach (var c in row)
                {
                    // Do nothing if there's nothing assignable for the cell
                    if (c != ' ')
                    {
                        Pos2D cellPos =
                            CalculatePrefabCellPosition(new Pos2D(x, y), upperLeft, prefabDimensions, flipY, flipX);

                        var cell = builder.BuildPrefabCell(c, cellPos, prefab);

                        // Respect the IsInvulnerable flag on prefabs
                        if (prefab.IsInvulnerable)
                        {
                            foreach (var wall in cell.Objects.Where(o => o.ObjectType == GameObjectType.Wall))
                            {
                                wall.SetInvulnerable();
                            }
                        }

                        builder.AddCell(cell, prefabGuid);
                    }

                    x++;
                }

                y++;
            }
        }