Beispiel #1
0
    void GenerateMap()
    {
        ChunkTemplates.GetFromTxt();

        Debug.Log(ChunkTemplates.templates[0][0][0]);

        GameObject start_ch = Instantiate(chunkPrefab, transform, false);

        start_ch.transform.localPosition = new Vector3(0, 5.5f);
        start_ch.GetComponent <Chunk>().GenerateChunk(0);
        Instantiate(camBoundary, new Vector3(-4.5f, 8), Quaternion.identity);

        for (int i = 1; i < mapLength - 1; i++)
        {
            GameObject ch = Instantiate(chunkPrefab, transform, false);
            ch.transform.localPosition = new Vector3(i * chunkDistance, 5.5f);
            ch.GetComponent <Chunk>().GenerateChunk(Random.Range(2, ChunkTemplates.templates.Count));
        }

        GameObject finish_ch = Instantiate(chunkPrefab, transform, false);

        finish_ch.transform.localPosition = new Vector3((mapLength - 1) * chunkDistance, 5.5f);
        finish_ch.GetComponent <Chunk>().GenerateChunk(1);
        Instantiate(camBoundary, new Vector3(finish_ch.transform.position.x + 12.25f, 8), Quaternion.identity);
    }
Beispiel #2
0
 /// <summary>
 /// Сохранение в файл с темплейтами
 /// </summary>
 public void SaveTemplate()
 {
     if (newTemplate)
     {
         SaveTemplateAsNew();
     }
     else
     {
         Debug.Log("Save existing template");
         ChunkTemplates.obstacleTemplatesContainer.templates[currentTemplateId] = GetTemplateMatrix();
         ChunkTemplates.SaveObstaclesToTxt();
     }
 }
Beispiel #3
0
 public void SaveTemplate()
 {
     if (newChunk)
     {
         SaveTemplateAsNew();
     }
     else
     {
         Debug.Log("Save existing template");
         ChunkTemplates.templates[tempId] = GetTemplateMatrix();
         ChunkTemplates.SaveToTxt();
     }
 }
Beispiel #4
0
 void SaveTemplateAsNew()
 {
     ChunkTemplates.obstacleTemplatesContainer.templates.Add(GetTemplateMatrix());
     ChunkTemplates.SaveObstaclesToTxt();
 }
Beispiel #5
0
 public void Start()
 {
     GenerateTemplate();
     ChunkTemplates.GetObstaclesFromJson();
 }
Beispiel #6
0
 public void Start()
 {
     ChunkTemplates.GetFromTxt();
     GenerateChunk();
     chunkIdText.text = "new";
 }
Beispiel #7
0
 public void SaveTemplateAsNew()
 {
     ChunkTemplates.templates.Add(GetTemplateMatrix());
     ChunkTemplates.SaveToTxt();
 }
Beispiel #8
0
 void SaveTemplateAsNew()
 {
     Debug.Log("Chunk SaveTemplateAsNew");
     ChunkTemplates.templatesContainer.templates.Add(GetTemplateMatrix());
     ChunkTemplates.SaveToTxt();
 }
Beispiel #9
0
 public void Start()
 {
     GenerateChunk();
     ChunkTemplates.GetFromJson();
 }
Beispiel #10
0
    void GenerateMapJson()
    {
        //Рекурсивно задаем гарантированный путь уровня
        GenerateMapLayout();

        //Выдаем лэйаут в консоль
        Debug.Log(mapLayout.ToDebugLogString("Map layout"));

        //Конвертируем лэйаут пути в улучшенный лэйаут, с учетом стен и прочего.
        mapLayout = ConvertLayout(mapLayout);

        //Выдаем лэйаут в консоль
        Debug.Log(mapLayout.ToDebugLogString("Converted map layout"));


        //Импортируем из джейсона
        ChunkTemplates.GetFromJson();
        ChunkTemplates.GetObstaclesFromJson();

        //create big map template, //!fill it with zeros
        int mapHeight = mapLayout.Length * ChunkTemplates.chunkHeight;
        int mapkWidth = mapLayoutLength * ChunkTemplates.chunkWidth;

        mapTemplate = new int[mapHeight][];
        for (int y = 0; y < mapHeight; y++)
        {
            mapTemplate[y] = new int[mapkWidth];
            for (int x = 0; x < mapkWidth; x++)
            {
                mapTemplate[y][x] = 0;
            }
        }

        //write all into mapTemplate
        for (int y = 0; y < mapLayout.Length; y++)
        {
            for (int x = 0; x < mapLayoutLength; x++)
            {
                int [][] templateMatrix = GenerateRandomByType(mapLayout[y][x]);
                for (int yM = 0; yM < templateMatrix.Length; yM++)
                {
                    for (int xM = 0; xM < templateMatrix[y].Length; xM++)
                    {
                        //if not obstacle space
                        if (templateMatrix[yM][xM] != 13)
                        {
                            mapTemplate[y * ChunkTemplates.chunkHeight + yM][x * ChunkTemplates.chunkWidth + xM] = templateMatrix[yM][xM];
                        }
                        //if obstacle
                        if (templateMatrix[yM][xM] == 12)
                        {
                            int[][] obstacleMatrix = ChunkTemplates.obstacleTemplatesContainer.templates.OrderBy(n => Random.value).FirstOrDefault().GetMatrix();
                            for (int yO = 0; yO < ChunkTemplates.obstacleHeight; yO++)
                            {
                                for (int xO = 0; xO < ChunkTemplates.obstacleWidth; xO++)
                                {
                                    mapTemplate[y * ChunkTemplates.chunkHeight + yM + yO][x * ChunkTemplates.chunkWidth + xM + xO] = obstacleMatrix[yO][xO];
                                }
                            }
                        }
                    }
                }
            }
        }

        //convert from BlockPlacerMatrix into BlockLibraryMatrix
        for (int y = 0; y < mapTemplate.Length; y++)
        {
            for (int x = 0; x < mapTemplate[y].Length; x++)
            {
                int type = mapTemplate[y][x];

                if (type == 0)
                {
                    continue;
                }
                bool flag = false;
                foreach (BlockPlacer.BlockChance blockChance in BlockPlacer.instance.blocks[type - 1].prefabs)
                {
                    if (Random.Range(0, blockChance.divider) == 0)
                    {
                        mapTemplate[y][x] = blockChance.blockLibraryId;
                        flag = true;
                        break;
                    }
                }
                if (!flag)
                {
                    mapTemplate[y][x] = 0;
                }
            }
        }

        Debug.Log(mapTemplate.ToDebugLogString("Converted to BlockLibraryMatrix map template"));


        //Set monsters
        for (int y = 1; y < mapTemplate.Length - 1; y++)
        {
            for (int x = 1; x < mapTemplate[y].Length - 1; x++)
            {
                if (mapTemplate[y][x] == 0 && mapTemplate[y][x - 1] == 0 && mapTemplate[y][x + 1] == 0 && mapTemplate[y + 1][x] == 1 && mapTemplate[y + 1][x - 1] == 1 && mapTemplate[y + 1][x + 1] == 1)
                {
                    Debug.Log("Found place for enemy to spawn!!");

                    if (Random.Range(0, 10) == 0)
                    {
                        mapTemplate[y][x] = 12; //charging skeleton
                    }
                    else
                    if (Random.Range(0, 5) == 0)
                    {
                        mapTemplate[y][x] = 2;    //regular skeleton
                    }
                }
                if (mapTemplate[y][x] == 0 && mapTemplate[y + 1][x] == 1 && mapTemplate[y - 1][x] == 1 &&
                    ((mapTemplate[y][x - 1] == 1 && mapTemplate[y][x + 1] == 0) || (mapTemplate[y][x - 1] == 0 && mapTemplate[y][x + 1] == 1)))
                {
                    if (Random.Range(0, 3) == 0)
                    {
                        mapTemplate[y][x] = 5;
                    }
                }
            }
        }



        //spawn blocks
        for (int y = 0; y < mapTemplate.Length; y++)
        {
            for (int x = 0; x < mapTemplate[y].Length; x++)
            {
                SpawnBlock(x, y, mapTemplate[y][x]);
            }
        }

        PrepareColliders();
    }