void Start() { Cursor.visible = false; RandomSeed = (int)System.DateTime.Now.Ticks; Random.InitState(RandomSeed); lastEndPosition = null; currEndPosition = null; if (Scenes.getParam("gridLenght") != "") { x = int.Parse(Scenes.getParam("gridLenght")); y = int.Parse(Scenes.getParam("gridHeight")); xStart = int.Parse(Scenes.getParam("xStart")) - 1; yStart = int.Parse(Scenes.getParam("yStart")) - 1; xEnd = int.Parse(Scenes.getParam("xEnd")) - 1; yEnd = int.Parse(Scenes.getParam("yEnd")) - 1; delay = 1f - float.Parse(Scenes.getParam("speed")) / 10; blocks = int.Parse(Scenes.getParam("blocks")); boostCount = int.Parse(Scenes.getParam("boost")); freezeCount = int.Parse(Scenes.getParam("freeze")); heightLevels = int.Parse(Scenes.getParam("DunesHeight")); acceleration = float.Parse(Scenes.getParam("acceleration")) / 10; blockRegeneration = bool.Parse(Scenes.getParam("blockRegeneration")); if (bool.Parse(Scenes.getParam("DisturbingF"))) { DisturbingSpawner.SetActive(true); } if (bool.Parse(Scenes.getParam("DecorativeF"))) { Spawner.SetActive(true); } if (heightLevels > 1) { climbing = true; } if (boostCount > 0) { boost = true; } if (freezeCount > 0) { freeze = true; } if (!blockRegeneration) { Blocks.text = "" + blocks; } else { Blocks.text = "" + 5; } } terrain.gameObject.SetActive(true); td = terrain.terrainData; td.size = new Vector3(x, heightLevels - 1, y); //terrain.transform.position -= Vector3((x - 1) / 2, 0, (y - 1) / 2); terrain.transform.position -= Vector3.right * .3f + Vector3.forward * .3f; terrain.GetComponent <PerlinTerrain>().Build(); Vector3 cameraPosition = terrain.transform.position + Vector3.up * Mathf.Max(x, y) * 2f + new Vector3((x - 1) / 2, 0, (y - 1) / 2) + Vector3.right * .5f; heightPerlin = terrain.GetComponent <PerlinTerrain>().GetH(); startingDelay = delay; // create a x * y matrix of nodes (and scene objects) // edge weight is now the geometric distance (gap) matrix = CreateGrid(x, y); //matrix = CreateGrid(sceneObject, x, y, gap); // create a graph and put random edges inside g = new Graph(); CreateGraph(g, matrix); currentNode = matrix[xStart, yStart]; previousNode = matrix[xStart, yStart]; visited.Add(currentNode); seenList.Add(currentNode); //seenGraph.AddNode(currentNode); //seenGraph.setConnections(currentNode, g.getConnections(currentNode)); if (boost) { insertSpecialBlocks(matrix, boostCount, 1, 1, boostMaterial, boostList); } if (freeze) { insertSpecialBlocks(matrix, freezeCount, 1 + heightLevels, 1 + heightLevels + 5, freezeMaterial, freezeList); } start = true; terrainSize = td.size; gridSize = new Vector2(x, y); startMaterial = Instantiate(startMaterial); startMaterial.transform.position = getNodePosition(matrix[xStart, yStart]) + Vector3.up; endMaterial.transform.position = getNodePosition(matrix[xEnd, yEnd]) + Vector3.up; RobotLight = startMaterial.GetComponentInChildren <Light>(); originaNpcColor = RobotLight.color; }
void Start() { RandomSeed = (int)System.DateTime.Now.Ticks; Random.InitState(RandomSeed); if (sceneObject != null) { if (Scenes.getParam("gridLenght") != "") { x = int.Parse(Scenes.getParam("gridLenght")); y = int.Parse(Scenes.getParam("gridHeight")); xStart = int.Parse(Scenes.getParam("xStart")) - 1; yStart = int.Parse(Scenes.getParam("yStart")) - 1; xEnd = int.Parse(Scenes.getParam("xEnd")) - 1; yEnd = int.Parse(Scenes.getParam("yEnd")) - 1; delay = 1f - float.Parse(Scenes.getParam("speed")) / 35; blocks = int.Parse(Scenes.getParam("blocks")); boostCount = int.Parse(Scenes.getParam("boost")); freezeCount = int.Parse(Scenes.getParam("freeze")); heightLevels = int.Parse(Scenes.getParam("DunesHeight")); acceleration = 1 + float.Parse(Scenes.getParam("acceleration")) / 1000f; blockRegeneration = bool.Parse(Scenes.getParam("blockRegeneration")); if (bool.Parse(Scenes.getParam("DisturbingF"))) { DisturbingSpawner.SetActive(true); } if (bool.Parse(Scenes.getParam("DecorativeF"))) { Spawner.SetActive(true); } if (heightLevels > 1) { climbing = true; } if (boostCount > 0) { boost = true; } if (freezeCount > 0) { freeze = true; } if (!blockRegeneration) { Blocks.text = "" + blocks; } else { Blocks.text = "" + 5; } } startingDelay = delay / 2; // create a x * y matrix of nodes (and scene objects) // edge weight is now the geometric distance (gap) matrix = CreateGrid(sceneObject, x, y, gap); // create a graph and put random edges inside g = new Graph(); CreateGraph(g, matrix); currentNode = matrix[xStart, yStart]; if (boost) { insertSpecialBlocks(matrix, boostCount, 1, 1, boostMaterial, boostList); } if (freeze) { insertSpecialBlocks(matrix, freezeCount, 1 + heightLevels, 1 + heightLevels + 5, freezeBlockMaterial, freezeList); } matrix[xEnd, yEnd].sceneObject.GetComponent <MeshRenderer>().material = endMaterial; float xCoord = (matrix[0, 0].sceneObject.transform.position.x + matrix[matrix.GetLength(0) - 1, 0].sceneObject.transform.position.x) / 2; float zCoord = (matrix[0, 0].sceneObject.transform.position.z + matrix[0, matrix.GetLength(1) - 1].sceneObject.transform.position.z) / 2; float yCoord = (Mathf.Max(matrix[matrix.GetLength(0) - 1, 0].sceneObject.transform.position.x - matrix[0, 0].sceneObject.transform.position.x, matrix[0, matrix.GetLength(1) - 1].sceneObject.transform.position.z - matrix[0, 0].sceneObject.transform.position.z) / 3.5f * -Mathf.Tan(30) / 2f) + 18; Vector3 cameraPosition = new Vector3(xCoord, yCoord, zCoord); GameObject.Find("Main Camera").transform.position = cameraPosition; OutlineNode(matrix[xStart, yStart], npcMaterial); } start = true; }