예제 #1
0
    public TerrainStructure(StoryStructure storyStructure, List <BiomeSettings> availableBiomes, float mapSize,
                            int heightMapResolution, int octaves,
                            int voronoiSamples, int lloydIterations, float heightNoise, float alphaNoise, float borderBlockerBlockerOffset)
    {
        AreaSegmentGraph   = new GrammarGraph <AreaSegment>();
        BorderBlockerLines = new List <Vector2[]>();
        AreaBlockerLines   = new List <Vector2[]>();
        MainPathLines      = new List <Vector2[]>();
        SidePathLines      = new List <Vector2[]>();
        PathPolygons       = new List <Vector2[]>();

        var filteredBiomes = availableBiomes;

        // Select a random biome out of the available ones for the current level
        if (GameController.Instance && availableBiomes.Count > 1)
        {
            filteredBiomes = availableBiomes.Where(biome => GameController.Instance.LastPlayedBiome != biome.UniqueName).ToList();
        }
        BiomeSettings = filteredBiomes[Random.Range(0, filteredBiomes.Count)];
        if (GameController.Instance)
        {
            GameController.Instance.LastPlayedBiome = BiomeSettings.UniqueName;
        }

        MapSize             = mapSize;
        HeightMapResolution = heightMapResolution;
        Octaves             = octaves;

        BorderSettings   = BiomeSettings.BorderBiome;
        _lloydIterations = lloydIterations;
        _voronoiSamples  = voronoiSamples;
        _heightNoise     = heightNoise;
        _alphaNoise      = alphaNoise;

        // Add splat prototypes to the shader
        CreateShaderTextures();

        // Create base graph that later on is transformed with a set of rules and assigned areas to
        CreateBaseGraph(lloydIterations);

        // Assign specific areas to each node of the base graph - Start point, Boss arena, paths...
        CreateAreaGraph(storyStructure.Rewrites);
        var startID = AreaSegmentGraph.FindNodesWithData(new AreaSegment(AreaSegment.EAreaSegmentType.Start))[0];

        Start = new KeyValuePair <Vector2, int>(_areaSegmentCenterMap[startID], startID);


        // Populate area segment blockers list
        CreateAreaBlockerLines();

        // Populate border lines list
        CreateBorderBlockerLines(borderBlockerBlockerOffset);

        // Populate path lines list
        CreatePathLines();

        // Create path polygons
        CreatePathPolygons(BiomeSettings.PathHalfWidth);
    }
예제 #2
0
    public SceneryStructure(StoryStructure storyStructure, TerrainStructure terrainStructure)
    {
        _graph = new GrammarGraph <AreaSegment>(terrainStructure.AreaSegmentGraph);

        // Assign speacial areas
        CreateSpecialAreas(terrainStructure);

        // Assign paths to area settings
        CreatePathAreas(terrainStructure);

        // Assign boss area segments to area settings
        CreateBossAreas(terrainStructure);
    }
예제 #3
0
    void Start()
    {
        if (instance == null)
        {
            instance = this;
        }
        else
        {
            Destroy(gameObject);
        }

        totalPages = 23;

        if (currentPage == 0)
        {
            currentPage = PlayerPrefs.GetInt("currentPage");
        }

        UpdateStoryPanel();
    }
예제 #4
0
    // Redraws preview in the scene editor
    public void GenerateLevel()
    {
#if UNITY_EDITOR
        if (!GenerateOnPlay && Application.isPlaying)
        {
            return;
        }
#endif

        Random.InitState(Seed);
        ClearDisplay();
        MyStoryStructure   = new StoryStructure(0, 1, MainPathNodeCount, SidePathCount, SidePathNodeCount, new CharacterEnemy[4]);
        MyTerrainStructure = new TerrainStructure(MyStoryStructure, AvailableBiomes, MapSize, HeightMapResolution, Octaves, VoronoiSamples, LloydRelaxation, HeightNoise, AlphaNoise, BorderBlockerOffset);
        MySceneryStructure = new SceneryStructure(MyStoryStructure, MyTerrainStructure);

        switch (DrawMode)
        {
        case DrawModeEnum.TerrainSkeleton:
            DrawTerrainSkeleton();
            break;

        case DrawModeEnum.Terrain:
            DrawTerrain();
            break;

        case DrawModeEnum.ScenerySkeleton:
            DrawScenerySkeleton();
            break;

        case DrawModeEnum.Scenery:
            DrawTerrainAndScenery();
            break;

        case DrawModeEnum.GameLevel:
            DrawCompleteLevel();
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }
    }