Esempio n. 1
0
 public static void FactoryDemo()
 {
     BlockFactory factory    = BlockFactorySingleton.GetInstance();
     Block        wall       = factory.CreateBlock("wall", 0, 0);
     Block        box        = factory.CreateBlock("wall", 0, 0);
     Block        teleporter = factory.CreateBlock("teleporter", 0, 0);
 }
Esempio n. 2
0
        public void PlaceBuilding(Point point, BuildingModel building, BlockModel[,,] blocks)
        {
            point = point - building.StartPoint;

            if (!CanYouPlaceBuilding(point, building, blocks))
            {
                return;
            }

            for (int x = 0; x < building.Width; x++)
            {
                for (int y = 0; y < building.Height; y++)
                {
                    for (int z = 0; z < building.Lenght; z++)
                    {
                        if (building.BuildingBlocks[x, y, z] != null)
                        {
                            int blocksX = x + point.X;
                            int blocksY = y + point.Y;
                            int blocksZ = z + point.Z;

                            blocks[blocksX, blocksY, blocksZ] = blockFactory.CreateBlock(new Point(blocksX, blocksY, blocksZ), building.BuildingBlocks[x, y, z].BlockType);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
    void MakeGround(int mapsizeH, int mapsizeW)
    {
        blockFactory = BlockFactory.instance;


        for (int i = 0; i < mapsizeH; i++)
        {
            for (int j = 0; j < mapsizeW; j++)
            {
                int data = liveMap.datas[i][j];

                if (i == 0 || i == mapsizeH - 1)
                {
                    data = BlockNumber.broken;
                }
                else if (j == 0 || j == mapsizeW - 1)
                {
                    data = BlockNumber.broken;
                }

                int   style_num = i * mapsizeW + j;
                Block newBlock  = blockFactory.CreateBlock(data, liveMap.styles[style_num], new Vector2(j, i));
                //Debug.Log(j + "," + i + " : " + newBlock.data);


                liveMap.SetBlocks(j, i, newBlock);
                if (newBlock.data == BlockNumber.normal || newBlock.data == BlockNumber.upperNormal)
                {
                    liveMap.UpdateCheckArray(j, i, false);
                }
                else if (newBlock.data >= BlockNumber.parfaitA && newBlock.data <= BlockNumber.parfaitD)
                {
                    liveMap.UpdateCheckArray(j, i, false);
                }
                else if (newBlock.data >= BlockNumber.upperParfaitA && newBlock.data <= BlockNumber.upperParfaitD)
                {
                    liveMap.UpdateCheckArray(j, i, false);
                }
                else if (newBlock.data == BlockNumber.character || newBlock.data == BlockNumber.upperCharacter)
                {
                    liveMap.UpdateCheckArray(j, i, false);
                }
                else
                {
                    liveMap.UpdateCheckArray(j, i, true);
                }
            }
        }
    }
Esempio n. 4
0
        public BlockModel[,,] GenerateBlockMap(int width, int height, int lenght)
        {
            BlockModel[,,] blocks = new BlockModel[width, height, lenght];

            int minHeight = 1;
            int maxHeight = 10;

            // Blocks[0, 0, 0] = BlockFactory.CreateBlock(new Point(0, 0, 0), BlockType.DirtBlock);

            for (int x = 0; x < width; x++)
            {
                for (int z = 0; z < lenght; z++)
                {
                    int h = calculateHeight(x, z, 3, blocks, minHeight, maxHeight);

                    h--;

                    int rng = randomService.GenerateInt(1, 101);

                    blocks[x, h, z] = BlockFactory.CreateBlock(new Point(x, h, z), BlockType.GrassBlock);

                    if (rng <= 1)
                    {
                        buildingService.PlaceBuilding(new Point(x, h + 1, z), new TreeBuilding(), blocks);
                        //blocks[x, h, z] = BlockFactory.CreateBlock(new Point(x, h, z), BlockType.DirtBlock);
                    }

                    for (int y = 0; y < h; y++)
                    {
                        blocks[x, y, z] = BlockFactory.CreateBlock(new Point(x, y, z), BlockType.DirtBlock);
                    }
                }
            }

            return(blocks);
        }
        private IEnumerable <BatchUpdateItem <LightBlockItem> > Fill(Column column)
        {
            var ground = BlockFactory.CreateBlock(BlockFactory.BlockDictionary.GetBlockIdForName("Grass"));
            var snow   = BlockFactory.CreateBlock(BlockFactory.BlockDictionary.GetBlockIdForName("Snow"));
            var trunk  = BlockFactory.CreateBlock(BlockFactory.BlockDictionary.GetBlockIdForName("TreeTrunk"));
            var leaves = BlockFactory.CreateBlock(BlockFactory.BlockDictionary.GetBlockIdForName("Leaves"));
            var dirt   = BlockFactory.CreateBlock(BlockFactory.BlockDictionary.GetBlockIdForName("Dirt"));
            var rock   = BlockFactory.CreateBlock(BlockFactory.BlockDictionary.GetBlockIdForName("Stone"));
            var trees  = GenerationManager.GetPlants(new Vector4(column.Offset.x - 8, column.Offset.y - 8,
                                                                 column.Offset.x + column.ChunkSize + 8,
                                                                 column.Offset.y + column.ChunkSize + 8));
            var columnBuffer = PoolManager.GetArrayPool <LightBlockItem[]>(column.MaxHeight).Pop();

            for (var x = 0; x < column.ChunkSize; ++x)
            {
                for (var z = 0; z < column.ChunkSize; ++z)
                {
                    var threshold = GenerationManager.GetHeight(column.Offset.x + x, column.Offset.y + z);
                    var distance  = ToClosestTree(trees, new Vector2Int(x + column.Offset.x, z + column.Offset.y));
                    var sunLight  = LightProcessor.ToLight(Colors.Black, Colors.White);
                    for (var height = column.MaxHeight - 1; height >= 0; --height)
                    {
                        IBlock block;
                        if (height > threshold)
                        {
                            if (distance.x <= 1 && height - distance.y <= 16)
                            {
                                sunLight = 0x0u;
                                block    = trunk;
                            }
                            else if (distance.x <= 4 && height - distance.y <= 18 && height - distance.y >= 8)
                            {
                                sunLight = 0x0u;
                                block    = leaves;
                            }
                            else
                            {
                                block = BlockFactory.Empty;
                            }
                        }
                        else if (height == threshold)
                        {
                            sunLight = 0x0u;
                            block    = ground;
                        }
                        else if (height > threshold - 2)
                        {
                            sunLight = 0x0u;
                            block    = dirt;
                        }
                        else
                        {
                            sunLight = 0x0u;
                            block    = rock;
                        }
                        columnBuffer[height] = new LightBlockItem
                        {
                            Block = block,
                            Light = sunLight
                        };
                    }

                    for (var y = 0; y < column.MaxHeight; ++y)
                    {
                        var bufferItem = columnBuffer[y];
                        yield return(new BatchUpdateItem <LightBlockItem>(new Vector3Int(x, y, z), bufferItem));
                    }
                }
            }
        }