// Start is called before the first frame update void Start() { mMapVisulisation = new Texture2D(PreviewSize.x, PreviewSize.y); MapGenerationPayload = new GenerationPayload(); MapGenerationPayload.size = PreviewSize; RebuildImageMap(); }
// Generate a new world using the save data public void GenerateWorld(Character Character, GenerationPayload generationPayload, Game.SaveDataPacket saveData) { mMapGenerationPayload = generationPayload; // Load the world save data GenerateWaterMap(saveData); Generate(saveData); SetupConnections(); // Move the player to there last position MovePlayerToStart(Character, mMap[saveData.PlayerX][saveData.PlayerY]); mCharacter = Character; // Load all entities for (int i = 0; i < saveData.Entities.Length; i++) { foreach (Entity e in EntityInstances) { if (saveData.Entities[i].N == e.entityName) { EnvironmentTile tile = mMap[saveData.Entities[i].X][saveData.Entities[i].Y]; Entity ent = GameObject.Instantiate(e, Environment.instance.transform); RegisterEntity(ent); ent.transform.position = tile.Position; ent.transform.rotation = Quaternion.identity; ent.CurrentPosition = tile; break; } } } }
// Generate a new world using the generation payload public void GenerateWorld(Character Character, GenerationPayload generationPayload) { // Define the generation payload mMapGenerationPayload = generationPayload; // Generate the worlds maps and load all tiles GenerateWaterMap(); Generate(); SetupConnections(); // Move the player to the start of the map MovePlayerToStart(Character, Start); mCharacter = Character; }
public static bool[,] GenerateWaterMap(GenerationPayload MapGenerationPayload) { // Create the return array bool[,] mapData = new bool[MapGenerationPayload.size.x, MapGenerationPayload.size.y]; Vector2Int Size = MapGenerationPayload.size; // Generate water map float perTileRadX = 3.14159f / Size.x; float perTileRadY = 3.14159f / Size.y; float[,] heightMap = new float[Size.x, Size.y]; for (int x = 0; x < Size.x; x++) { for (int y = 0; y < Size.y; y++) { // Calculate x and y coordinates based on the maps size / frequency float xCoord = ((float)x / (float)Size.x) * MapGenerationPayload.frequancy; float yCoord = ((float)y / (float)Size.y) * MapGenerationPayload.frequancy; // Generate the height map for the tile using the perlin noise function heightMap[x, y] = Mathf.PerlinNoise(xCoord, yCoord) + ((Mathf.Sin(perTileRadX * x) + Mathf.Sin(perTileRadY * y)) * MapGenerationPayload.amplitude); } } // calculate the average tile height float average = 0.0f; for (int x = 0; x < Size.x; x++) { for (int y = 0; y < Size.y; y++) { average += heightMap[x, y]; } } // Normalize the average to a range of 0-1 average /= (Size.x * Size.y); average *= MapGenerationPayload.waterHeight; // Generate the final water map, checking to see if the height map is less then the calculated average for (int x = 0; x < Size.x; x++) { for (int y = 0; y < Size.y; y++) { mapData[x, y] = heightMap[x, y] < average; } } return(mapData); }
// Start is called before the first frame update void Start() { SceneManager.LoadScene("Music-SFX", LoadSceneMode.Additive); // Init the music levels { MainMusicSlider.value = PlayerPrefs.GetFloat("MainVol", -20); MusicMixer.SetFloat("MainVol", MainMusicSlider.value); UISlider.value = PlayerPrefs.GetFloat("UIVol", -20); UIMixer.SetFloat("UIVol", UISlider.value); MusicMixer.SetFloat("NightTimeMusicVol", -80); MusicMixer.SetFloat("MusicVol", 0); } // Generate a example game scene { mCharacter = Instantiate(Character, transform); mCharacter.transform.position = CharacterStart.position; mCharacter.transform.rotation = CharacterStart.rotation; BackgroundGenerationPayload = new GenerationPayload(); // Define the generation settings BackgroundGenerationPayload.amplitude = IslandAmplitude; BackgroundGenerationPayload.frequancy = IslandFrequancy; BackgroundGenerationPayload.waterHeight = IslandWaterHeight; BackgroundGenerationPayload.size = IslandSize; // Finally generate the world BackgroundEnviroment.GenerateWorld(mCharacter, BackgroundGenerationPayload); BackgroundEnviroment.transform.RotateAround(BackgroundEnviroment.transform.position, transform.up, IslandStartRotation); } // Setup settings { // Loop through all the graphics settings and add them to the settings panel string[] names = QualitySettings.names; GraphicsQualityDropdown.ClearOptions(); List <TMP_Dropdown.OptionData> qualityOptions = new List <TMP_Dropdown.OptionData>(); int currentQuality = QualitySettings.GetQualityLevel(); foreach (string qualityName in names) { TMP_Dropdown.OptionData optionData = new TMP_Dropdown.OptionData(qualityName); qualityOptions.Add(optionData); } GraphicsQualityDropdown.AddOptions(qualityOptions); GraphicsQualityDropdown.value = currentQuality; } }