示例#1
0
 public void Randomize()
 {
     LoggerTool.Post("Generate a randomize island for preview");
     generator.useRandomSeed = true;
     UpdateInputValue();
     generator.GenerateIsland();
 }
    float[,] GenerateMapData()
    {
        float[,] noiseMap = NoiseGenerator.NoiseMap(terrainControl.mapSize, terrainControl);

        //if were using the island map
        if (terrainControl.useIsland)
        {
            terrainControl.IslandMap = IslandGenerator.GenerateIsland(terrainControl.mapSize);
        }

        for (int y = 0; y < terrainControl.mapSize; y++)
        {
            for (int x = 0; x < terrainControl.mapSize; x++)
            {
                //if were using the IslandMap the apply it
                if (terrainControl.useIsland)
                {
                    //combine both maps, and clamp value between 0-1
                    noiseMap[x, y] = Mathf.Clamp01(noiseMap[x, y] - terrainControl.IslandMap[x, y]);
                }
            }
        }

        textureControl.UpdateTextures(terrainControl.minHeight, terrainControl.maxHeight, terrainMaterial);

        return(noiseMap);
    }
    public override void OnInspectorGUI()
    {
        IslandGenerator islandGen = target as IslandGenerator;

        if (DrawDefaultInspector())
        {
            if (islandGen.autoUpdate)
            {
                islandGen.GenerateIsland();
            }
        }

        GUILayout.Space(10);
        if (GUILayout.Button("Generate"))
        {
            islandGen.GenerateIsland();
        }
    }
    public override void OnInspectorGUI()
    {
        IslandGenerator islandGen = target as IslandGenerator;

        if (DrawDefaultInspector())
        {
            if (islandGen.autoUpdate)
            {
                LoggerTool.Post("Generate island from Editor");
                islandGen.GenerateIsland(false);
            }
        }

        GUILayout.Space(10);
        if (GUILayout.Button("Generate"))
        {
            LoggerTool.Post("Generate island from Editor");
            islandGen.GenerateIsland(false);
        }
    }
    void Update()
    {
        if (Input.GetButtonDown("Fire1"))
        {
            LoggerTool.Post("Start generating island from a click");
            bool prevRandSet = islandGenerator.useRandomSeed;
            islandGenerator.useRandomSeed = useRandomSeed;
            startedRecording = true;
            clock.Start();
            islandGenerator.GenerateIsland();
            islandGenerator.useRandomSeed = prevRandSet;
        }

        if (startedRecording && islandGenerator.IsDone())
        {
            startedRecording = false;
            LoggerTool.Post("Generated with " + clock.Elapsed() + " seconds.");
            LoggerTool.Post(" ----------------------- ");
        }
    }
 /// <summary>
 /// Calls functions which generate island
 /// </summary>
 public void GenerateIsland()
 {
     generator.DetermineSize();
     generator.GenerateIsland();
 }
 public void Randomize()
 {
     generator.useRandomSeed = true;
     UpdateInputValue();
     generator.GenerateIsland();
 }
示例#8
0
    IEnumerator SpawnIslands()
    {
        while (true)
        {
            float halfCamHeight = cam.orthographicSize;
            float halfCamWidth  = halfCamHeight * cam.aspect;

            // Get generated island object
            GameObject island = islandGenerator.GenerateIsland();
            island.GetComponent <Island>().map = map;

            // Check if homeIsland exists
            if (!homeIsland)
            {
                Destroy(island);
                // Generate wait time until next island spawning
                yield return(new WaitForSeconds(spawnCooldown.GetRandom()));

                continue;
            }

            // Randomly choose whether this island is vertically-moving or horizontally-moving
            if (Random.value < 0.5f)
            {
                // Vertically-moving island
                RandomValue spawnXRange = new RandomValue(cam.transform.position.x - halfCamWidth, cam.transform.position.x + halfCamWidth);
                spawnXRange.SetExcludedRange(new Range(GetChildBounds(homeIsland).min.x - homeBuffer - GetChildBounds(island).extents.x, GetChildBounds(homeIsland).max.x + homeBuffer + GetChildBounds(island).extents.x));
                float newIslandX = spawnXRange.GetRandom();
                // Randomly choose whether this island spawns from top or bottom
                if (Random.value < 0.5f)
                {
                    // Island spawns from top and moves down
                    float   newIslandY        = cam.transform.position.y + halfCamHeight + GetChildBounds(island).extents.y;
                    Vector3 newIslandPosition = new Vector3(newIslandX, newIslandY, island.transform.position.z);
                    // Move island to randomly generated position
                    island.transform.position = newIslandPosition;
                    island.GetComponent <Rigidbody2D>().velocity = new Vector2(0, -islandVelocity.GetRandom());
                }
                else
                {
                    // Island spawns from bottom and moves up
                    float   newIslandY        = cam.transform.position.y - halfCamHeight - GetChildBounds(island).extents.y;
                    Vector3 newIslandPosition = new Vector3(newIslandX, newIslandY, island.transform.position.z);
                    island.transform.position = newIslandPosition;
                    island.GetComponent <Rigidbody2D>().velocity = new Vector2(0, islandVelocity.GetRandom());
                }
            }
            else
            {
                // Horizontally-moving island
                RandomValue spawnYRange = new RandomValue(cam.transform.position.y - halfCamHeight, cam.transform.position.y + halfCamHeight);
                spawnYRange.SetExcludedRange(new Range(GetChildBounds(homeIsland).min.y - homeBuffer - GetChildBounds(island).extents.y, GetChildBounds(homeIsland).max.y + homeBuffer + GetChildBounds(island).extents.y));
                float newIslandY = spawnYRange.GetRandom();
                // Randomly choose whether this island spawns from left or right
                if (Random.value < 0.5f)
                {
                    // Island spawns from left and moves right
                    float   newIslandX        = cam.transform.position.x + halfCamWidth + GetChildBounds(island).extents.x;
                    Vector3 newIslandPosition = new Vector3(newIslandX, newIslandY, island.transform.position.z);
                    island.transform.position = newIslandPosition;
                    island.GetComponent <Rigidbody2D>().velocity = new Vector2(-islandVelocity.GetRandom(), 0);
                }
                else
                {
                    // Island spawns from right and moves left
                    float   newIslandX        = cam.transform.position.x - halfCamWidth - GetChildBounds(island).extents.x;
                    Vector3 newIslandPosition = new Vector3(newIslandX, newIslandY, island.transform.position.z);
                    island.transform.position = newIslandPosition;
                    island.GetComponent <Rigidbody2D>().velocity = new Vector2(islandVelocity.GetRandom(), 0);
                }
            }
            // Generate wait time until next island spawning
            yield return(new WaitForSeconds(spawnCooldown.GetRandom()));
        }
    }
 void PlayerDied()
 {
     // Just restart them for now
     generator.GenerateIsland();
     currentHealth = startingHealth;
 }
 void Start()
 {
     SetLevelSeed();
     clock.Start();
     generator.GenerateIsland();
 }