Пример #1
0
    public TerrainLayer SetUpTerrainLayer(World world, Noise noise)
    {
        this.world = world;
        this.noiseGen = noise;
        if (layerType == LayerType.Structure)
        {
            var type = Type.GetType(structureClassName + ", " + typeof(GeneratedStructure).Assembly);
            structure = (GeneratedStructure)Activator.CreateInstance(type);
        }

        return this;
    }
Пример #2
0
    public TerrainLayer SetUpTerrainLayer(World world, Noise noise)
    {
        this.world    = world;
        this.noiseGen = noise;
        if (layerType == LayerType.Structure)
        {
            var type = Type.GetType(structureClassName + ", " + typeof(GeneratedStructure).Assembly);
            structure = (GeneratedStructure)Activator.CreateInstance(type);
        }

        return(this);
    }
Пример #3
0
    protected override void SetUp(LayerConfig config)
    {
        // Config files for random layers MUST define these properties
        chance = float.Parse(properties["chance"]);

        var structureType = Type.GetType(config.structure + ", " + typeof(GeneratedStructure).Assembly, false);

        if (structureType == null)
        {
            Debug.LogError("Could not create structure " + config.structure);
        }

        structure = (GeneratedStructure)Activator.CreateInstance(structureType);
    }
Пример #4
0
    public void AttemptStructureGeneration(int x, int y)//Will attempt to generate a structure in a certain location based on biomes. Not even the creator fully understands!
    {
        generatedStructurePositions.Add(generateKey(x, y), true);

        List <Biome> biomes = GetBiomesFromPosition(x, y);

        if (biomes.Count == 1)
        {
            Biome biome = biomes[0];

            if (Random.Range(0, biome.generationSparseness - 1) != 0)
            {
                return;                                                      //Makes generation more sparse.
            }
            int random = Random.Range(0, biome.weightSum);

            for (int i = 0; i < biome.generatedStructures.Length; i++)
            {
                GeneratedStructure structure = biome.generatedStructures[i];

                if (random >= biome.weightMap[i] && random < biome.weightMap[i] + structure.generationWeight - 1) //A bizarre comparison that compares whether the random number will attempt to generate a certain structure.
                {
                    structure.transform.position = new Vector2(x, y);                                             // Offsets the prefab. Not sure if this will be a problem in the future.

                    bool collision = CheckStructureCollisions(structure.gameObject);

                    if (!collision)  //Makes sure there are no collsions happening.

                    {
                        return;
                    }

                    GameObject instance = Instantiate(biome.generatedStructures[i].gameObject, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;

                    RegisterStructureTiles(instance);

                    return;
                }
            }
        }
    }
    /// <summary>
    /// Places all generated structures in order
    /// </summary>
    private void PlaceGeneratedStructures(GeneratedStructure structure, int count)
    {
        List <Room> roomPos = rooms.Values.ToList();

        for (int i = 0; i < count; i++)
        {
            Room randomRoom;
            do
            {
                if (roomPos.Count == 0)
                {
                    Debug.LogError("Too many generated structures for one level: Increase the number of rooms.");
                    return;
                }
                randomRoom = roomPos[Random.Range(0, roomPos.Count)];
                roomPos.Remove(randomRoom);
            } while (!structure.CanGenerate(walls, upperFloor, ceiling, randomRoom));

            structure.Generate(walls, upperFloor, ceiling, randomRoom);
        }
    }