Beispiel #1
0
    public void OnPlayerMove()
    {
        Vector2 playerPos = FindObjectOfType <Player>().transform.position;
        Vector2 roomPos   = new Vector2(((int)playerPos.x + 6) / 12, ((int)playerPos.y + 6) / 12);

        UI.instance.map.texture = MapTextureGenerator.Generate(map, roomPos);
    }
Beispiel #2
0
    public void Generate()
    {
        map = new bool[mapWidth, mapHeight];
        CheckRoom(3, 3, 0, Vector2.zero, true);
        InstantiateRooms();
        FindObjectOfType <Player>().transform.position = firstRoomPos * 12;

        UI.instance.map.texture = MapTextureGenerator.Generate(map, firstRoomPos);
    }
        void OnMapDataReceived(MapData mapData)
        {
            this.mapData    = mapData;
            mapDataReceived = true;

            Texture2D t = MapTextureGenerator.TextureFromColorMap(mapData.colorMap, MapGenerator.mapChunkSize, MapGenerator.mapChunkSize);

            meshRenderer.material.mainTexture = t;

            UpdateTerrainChunk();
        }
Beispiel #4
0
    public void GenerateMap()
    {
        var startTime = DateTime.Now;
        var points    = GetPoints();

        var time    = DateTime.Now;
        var voronoi = new Delaunay.Voronoi(points, null, new Rect(0, 0, meshSize, meshSize), relaxationIterations);

        //Debug.Log(string.Format("Voronoi Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        heightMapSettings.noiseSettings.seed = seed;
        var heightMap = HeightMapGenerator.GenerateHeightMap(meshSize, meshSize, heightMapSettings, Vector2.zero);

        _heightMap = heightMap;
        //Debug.Log(string.Format("Heightmap Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        var mapGraph = new MapGraph(voronoi, heightMap, snapDistance);

        _mapGraph = mapGraph;
        //Debug.Log(string.Format("Finished Generating Map Graph: {0:n0}ms with {1} nodes", DateTime.Now.Subtract(startTime).TotalMilliseconds, mapGraph.nodesByCenterPosition.Count));

        time = DateTime.Now;
        MapGenerator.GenerateMap(mapGraph);
        //Debug.Log(string.Format("Map Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        Vector3 born = MapGenerator.getBorn();

        //Debug.Log(string.Format("Born: {0},{1},{2}", born.x,born.y,born.z));

        if (previewType == PreviewType.HeightMap)
        {
            OnMeshDataReceived(MapMeshGenerator.GenerateMesh(mapGraph, heightMap, meshSize));
            UpdateTexture(TextureGenerator.TextureFromHeightMap(heightMap));
        }
        if (previewType == PreviewType.Map)
        {
            time = DateTime.Now;
            OnMeshDataReceived(MapMeshGenerator.GenerateMesh(mapGraph, heightMap, meshSize));
            //Debug.Log(string.Format("Mesh Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

            time = DateTime.Now;
            var texture = MapTextureGenerator.GenerateTexture(mapGraph, meshSize, textureSize, colours, drawNodeBoundries, drawDelauneyTriangles, drawNodeCenters);
            //Debug.Log(string.Format("Texture Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

            UpdateTexture(texture);
        }

        Debug.Log(string.Format("Finished Generating World: {0:n0}ms with {1} nodes", DateTime.Now.Subtract(startTime).TotalMilliseconds, mapGraph.nodesByCenterPosition.Count));
    }
Beispiel #5
0
    public void GenerateMap()
    {
        var startTime = DateTime.Now;
        var points    = GetPoints();

        var time    = DateTime.Now;
        var voronoi = new Delaunay.Voronoi(points, null, new Rect(0, 0, meshSize, meshSize));

        Debug.Log(string.Format("Voronoi Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        heightMapSettings.noiseSettings.seed = seed;
        var heightMap = HeightMapGenerator.GenerateHeightMap(meshSize, meshSize, heightMapSettings, Vector2.zero);

        Debug.Log(string.Format("Heightmap Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        var mapGraph = new MapGraph(voronoi, heightMap, snapDistance);

        Debug.Log(string.Format("Finished Generating Map Graph: {0:n0}ms with {1} nodes", DateTime.Now.Subtract(time).TotalMilliseconds, mapGraph.nodesByCenterPosition.Count));

        time = DateTime.Now;
        MapGenerator.GenerateMap(mapGraph);
        Debug.Log(string.Format("Map Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        OnMeshDataReceived(MapMeshGenerator.GenerateMesh(mapGraph, meshSize));
        Debug.Log(string.Format("Mesh Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        var texture = MapTextureGenerator.GenerateTexture(mapGraph, meshSize, textureSize, colours, drawNodeBoundries, drawDelaunayTriangles);

        Debug.Log(string.Format("Texture Generated: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        UpdateTexture(texture);

        time = DateTime.Now;
        EnvironmentSpawner.Spawn(mapGraph, GameObject.Find("Environment").transform, environmentSettings, seed);
        Debug.Log(string.Format("Environment Spawned: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        time = DateTime.Now;
        AnimalSpawner.Spawn(mapGraph, GameObject.Find("Animals").transform, animalSettings, seed);
        Debug.Log(string.Format("Animals Spawned: {0:n0}ms", DateTime.Now.Subtract(time).TotalMilliseconds));

        Debug.Log(string.Format("Finished Generating World: {0:n0}ms with {1} nodes", DateTime.Now.Subtract(startTime).TotalMilliseconds, mapGraph.nodesByCenterPosition.Count));
    }
Beispiel #6
0
    public void DrawMapInEditor()
    {
        MapData mData = GenerateMapData(Vector2.zero);

        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (drawMode == DrawMode.NoiseMap)
        {
            display.DrawTexture(MapTextureGenerator.TextureFromHeightMap(mData.heightMap));
        }
        else if (drawMode == DrawMode.ColorMap)
        {
            display.DrawTexture(MapTextureGenerator.TextureFromColorMap(mData.colorMap, mapChunkSize, mapChunkSize));
        }
        else if (drawMode == DrawMode.Mesh)
        {
            display.DrawMesh(MapMeshGenerator.GenerateTerrainMesh(mData.heightMap, meshHeightMultiplier, meshHeightCurve, editorPreviewLOD), MapTextureGenerator.TextureFromColorMap(mData.colorMap, mapChunkSize, mapChunkSize));
        }
    }
    public void generateMap(Config conf)
    {
        Random.InitState(conf.seed);

        var points  = PointsGenerator.getPoints(conf);
        var voronoi = new Delaunay.Voronoi(points, null, new Rect(0, 0, conf.meshSize, conf.meshSize), conf.relaxationIterations);

        var elevationMap = ElevationMapGenerator.generate(conf);

        var mapGraph = new MapGraph(voronoi, elevationMap);

        BiomeMapGenerator.generate(mapGraph, conf);

        updateMesh(MapMeshGenerator.generate(mapGraph, meshSize));
        updateTexture(MapTextureGenerator.generate(mapGraph, conf));

        EvaluationResults evaluation = Evaluation.assessmentResultsToString(mapGraph, conf);

        beachFunction    = evaluation.beachFunction;
        mountainFunction = evaluation.mountainFunction;
        lowlandFunction  = evaluation.lowlandFunction;
        Debug.Log(evaluation.result);
    }
Beispiel #8
0
    public void BuildMap()
    {
        spawnWaves = SpawnWavesFromMapTexture(mapTexture);

        for (int i = 0; i < spawnWaves.Length; i++)
        {
            RandomizeArray(spawnWaves[i].spawnings, random);
        }

        mapObject       = new GameObject("Map", typeof(MeshFilter), typeof(MeshRenderer), typeof(MeshCollider));
        mapObject.layer = LayerMask.NameToLayer("Ground");

        grid = new Grid(map);

        mapMesh = map.BuildMesh();
        mapObject.GetComponent <MeshFilter>().mesh = mapMesh;

        var material = new Material(LevelBootstrap.mapMaterial);

        mapObject.GetComponent <MeshRenderer>().material = material;

        mapTexture           = MapTextureGenerator.Generate(map, 2048);
        material.mainTexture = mapTexture;

        var collider = mapObject.GetComponent <MeshCollider>();

        collider.inflateMesh = true;
        collider.sharedMesh  = mapMesh;

        SpawnBreakables(TileType.WeakWall, LevelBootstrap.brickBlockPrefab);
        SpawnBreakables(TileType.StrongWall, LevelBootstrap.concreteBlockPrefab);

        SpawnProps(TileType.Water, LevelBootstrap.waterPrefab);
        SpawnRandomProps(TileType.Woods, LevelBootstrap.RandomTree);

        enemySpawnPoints = map.EnemySpawnPoints();
        RandomizeArray(enemySpawnPoints, random);

        var basePosition = map.BasePosition();

        enemyController.playerBasePosition = basePosition;
        playerBaseBreakable =
            Object.Instantiate(LevelBootstrap.playerBasePrefab, basePosition, Quaternion.identity, mapObject.transform);
        playerBaseBreakable.OnBreak += defeatCallback;

        // Tank base colour
        float       hue        = (float)random.NextDouble() % 1f;
        const float saturation = 0.7f;
        const float value      = 0.7f;

        enemyController.tankBaseColor = new ColorHSV(hue, saturation, value);

        BuildCollidersOnEdges();


        // Set Background color and create same coloured plane on ground to hide tanks spawning underneath map
        var backgroundColor = LevelBootstrap.RandomSkyColor(random);

        Camera.main.backgroundColor = backgroundColor;
        RenderSettings.ambientLight = backgroundColor;

        var hideBelowGroundObject = GameObject.CreatePrimitive(PrimitiveType.Plane);

        hideBelowGroundObject.name = "Hide Below Ground";
        hideBelowGroundObject.transform.position   = new Vector3(map.size / 2f, -0.0001f, map.size / 2f);
        hideBelowGroundObject.transform.localScale = Vector3.one * 2 * map.size;
        hideBelowGroundObject.transform.parent     = mapObject.transform;

        var hideBelowMaterial = new Material(Shader.Find("Unlit/Color"));

        hideBelowMaterial.color = backgroundColor;
        hideBelowGroundObject.GetComponent <Renderer>().material = hideBelowMaterial;
    }     // build map