private void Update() { if (map == null) { map = FindObjectOfType <mapTile>(); } }
//public Generate_Terrain terr; // Use this for initialization void Start() { //map = terr.mainMap.GetComponent<mapTile>(); m_Dropdown = GetComponent <Dropdown>(); m_Dropdown.onValueChanged.AddListener(delegate { ChangeLocation(m_Dropdown); }); if (map == null) { map = FindObjectOfType <mapTile>(); } locationFunctionPairs = new Dictionary <string, Action>(); locationFunctionPairs.Add("Canmore", () => map.ChangeTile(51.2894f, -115.4f, 11, location: "Canmore")); locationFunctionPairs.Add("Monte Vista", () => map.ChangeTile(37.7f, -106.35f, 11, location: "Monte Vista")); locationFunctionPairs.Add("Everest", () => map.ChangeTile(28.1000f, 86.8658f, 11, 'a', 0, 0, 4, location: "Everest")); locationFunctionPairs.Add("Cliffs of Dover", () => map.ChangeTile(51.1345f, 1.3573f, 15, 'a', -3, -1, 4, location: "Cliffs of Dover")); locationFunctionPairs.Add("Monument Valley", () => map.ChangeTile(37.048f, -110.122f, 13, 'a', -3, -2, 1, location: "Monument Valley")); locationFunctionPairs.Add("Grand Canyon", () => map.ChangeTile(36.2144f, -113.0565f, 13, 'a', 0, -1, location: "Grand Canyon")); locationFunctionPairs.Add("Blanca Peak", () => map.ChangeTile(37.57f, -105.48f, 12, 'a', -2, -2, location: "Blanca Peak")); locationFunctionPairs.Add("Sierro del Ojito", () => map.ChangeTile(37.29f, -105.80f, 14, location: "Sierro del Ojito")); locationFunctionPairs.Add("Mount Waialeale", () => map.ChangeTile(22.0707f, -159.4961f, 12, mXOffset: -2, mYOffset: -2, location: "Mount Waialeale")); locationFunctionPairs.Add("Mount Wutai", () => map.ChangeTile(36.0076f, 113.5963f, 13, mXOffset: -1, mYOffset: 1, location: "Mount Wutai")); locationFunctionPairs.Add("Grotto Canyon 15", () => map.ChangeTile(51.0646f, -115.2033f, 15, mXOffset: -2, mYOffset: -2, location: "Grotto Canyon")); locationFunctionPairs.Add("Grotto Canyon 14", () => map.ChangeTile(51.0646f, -115.2033f, 14, mXOffset: -2, mYOffset: -2, location: "Grotto Canyon")); locationFunctionPairs.Add("Grotto Canyon 13", () => map.ChangeTile(51.0646f, -115.2033f, 13, mXOffset: -2, mYOffset: -2, location: "Grotto Canyon")); locationFunctionPairs.Add("Grotto Canyon 12", () => map.ChangeTile(51.0646f, -115.2033f, 12, mXOffset: -2, mYOffset: -2, location: "Grotto Canyon")); m_Dropdown.options = new List <Dropdown.OptionData>(); m_Dropdown.AddOptions(locationFunctionPairs.Keys.ToList()); }
private IEnumerator startNewTask(mapTile map) { yield return new WaitUntil(() => !map.isLoadingTile); yield return new WaitUntil(() => Input.touchCount > 0); time = Time.time; answerLock = false; }
// Update is called once per frame void Update() { if (map == null) { map = FindObjectOfType <mapTile>(); map.OnTileLoad += loadingState; } }
private void ChangeLoc(int val) { if (map == null) { map = FindObjectOfType <mapTile>(); } locationFunctionPairs[m_Dropdown.options[val].text](); /* * * switch (val) * { * case 0: * locationFunctionPairs["Canmore"](); * //map.ChangeTile(51.2894f, -115.4f, 11); //Canmore * break; * case 1: * locationFunctionPairs["Monte Vista"](); * //map.ChangeTile(37.7f, -106.35f, 11); //Monte Vista * break; * case 2: * locationFunctionPairs["Everest"](); * //map.ChangeTile(28.1000f, 86.8658f, 11, 'a', 0, 0, 4); //Everest * break; * case 3: * locationFunctionPairs["Monument Valley"](); * //map.ChangeTile(37.048f, -110.122f, 13, 'a', -3, -2, 1); //Monument valley * break; * case 4: * locationFunctionPairs["Cliffs of Dover"](); * //map.ChangeTile(51.1345f, 1.3573f, 15, 'a', -3, -1, 4); //Cliffs of Dover * break; * case 5: * locationFunctionPairs["Grand Canyon"](); * //map.ChangeTile(36.2144f, -113.0565f, 13, 'a', -2, -2); //Grand Canyon * break; * case 6: * locationFunctionPairs["Blanca Peak"](); * //map.ChangeTile(37.57f, -105.48f, 12, 'a', -2, -2); //Blanca Peak * break; * case 7: * locationFunctionPairs["Sierro del Ojito"](); * //map.ChangeTile(37.29f, -105.80f, 14); //Sierro del Ojito * break; * case 8: * locationFunctionPairs["Mount Waialeale"](); * break; * case 9: * locationFunctionPairs["Mount Wutai"](); * break; * } */ }
//public Vector2Int tileDimentions = new Vector2Int(8, 6); void Awake() { zombiePaths = new bool[Width, Height][, ]; Vector2Int startPos = new Vector2Int(Mathf.RoundToInt(Width * 0.5f), Mathf.RoundToInt(Height * 0.5f)); Vector2Int currentPos = startPos; Vector2Int currentDir = directions[Random.Range(0, 1), Random.Range(0, 1)]; //random direction int distance = 0; int roomCounter = 0; mapPaths[(int)currentPos.x, (int)currentPos.y] = true; for (int moves = 0; moves < WalkerPaths; moves++) { //Change Direction, move away from map bounds if near it if (currentDir == Vector2Int.up || currentDir == Vector2Int.down) { if (currentPos.x <= 1) { currentDir = Vector2Int.right; } else if (currentPos.x >= Width - 1) { currentDir = Vector2Int.left; } else { currentDir = directions[1, Mathf.RoundToInt(Mathf.Clamp(Random.Range(0f, 1f) * RightLeftBias, 0f, 1f))]; // left/right } } else { if (currentPos.y <= 1) { currentDir = Vector2Int.up; } else if (currentPos.y >= Height - 1) { currentDir = Vector2Int.down; } else { currentDir = directions[0, Mathf.RoundToInt(Mathf.Clamp(Random.Range(0f, 1f) * DownUpBias, 0f, 1f))]; // up/down } } if (currentDir == Vector2Int.up) { distance = Random.Range(1, (int)((Height - currentPos.y) * yBias)); } else if (currentDir == Vector2Int.down) { distance = Random.Range(1, (int)(currentPos.y * yBias)); } else if (currentDir == Vector2Int.left) { distance = Random.Range(1, (int)(currentPos.x * xBias)); } else if (currentDir == Vector2Int.right) { distance = Random.Range(1, (int)((Width - currentPos.x) * xBias)); } else { Debug.Log("Error"); } //Debug.Log("Distance: " + distance + currentDir); for (int step = 0; step < distance; step++) { currentPos += currentDir; //Debug.Log("Position: " + currentPos); mapPaths[(int)currentPos.x, (int)currentPos.y] = true; if (moves == WalkerPaths - 1) { Instantiate(exit, new Vector3(currentPos.x * 10 - 2495, currentPos.y * 10 - 2498, 0), transform.rotation); } //Debug.Log("Current Position: " + currentPos.x + ", " + currentPos.y); } } //generate map for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { if (mapPaths[x, y]) { int thisRoomShape = new mapTile(mapPaths[x, y + 1], mapPaths[x, y - 1], mapPaths[x - 1, y], mapPaths[x + 1, y]).shape; GameObject thisRoom = rooms[thisRoomShape].list[Random.Range(0, rooms[thisRoomShape].list.Count)]; Tilemap roomPaths = null; foreach (Transform t in thisRoom.transform) { if (t.name == "Walls") { thisWall = t.gameObject.GetComponent <Tilemap>(); } else if (t.name == "Platform") { thisPlatform = t.gameObject.GetComponent <Tilemap>(); } else if (t.name == "Stairs (Right)") { thisStairR = t.gameObject.GetComponent <Tilemap>(); } else if (t.name == "Stairs (Left)") { thisStairL = t.gameObject.GetComponent <Tilemap>(); } else if (t.name == "Zombie Paths") { roomPaths = t.gameObject.GetComponent <Tilemap>(); } else if (t.name == "Objects") { objects = t.gameObject; foreach (Transform item in objects.transform) { Instantiate(item.gameObject, new Vector3(x * roomSize.x + item.position.x, y * roomSize.y + item.position.y, 0), item.rotation, transform.Find("Objects")); } //Instantiate(t.gameObject,new Vector3(x * roomSize.x - startPos.x * roomSize.x, y * roomSize.y - startPos.y * roomSize.y, 0), t.rotation, transform); } else { Debug.Log("We couldn't find the obejct you are looking for..."); } } zombiePaths[x, y] = new bool[roomSize.x, roomSize.y]; //generate room for (int mx = 0; mx < roomSize.x; mx++) { for (int my = 0; my < roomSize.y; my++) { walls.SetTile(new Vector3Int(x * roomSize.x + mx, y * roomSize.y + my, 0), thisWall.GetTile(new Vector3Int(mx, my, 0))); platform.SetTile(new Vector3Int(x * roomSize.x + mx, y * roomSize.y + my, 0), thisPlatform.GetTile(new Vector3Int(mx, my, 0))); stairRight.SetTile(new Vector3Int(x * roomSize.x + mx, y * roomSize.y + my, 0), thisStairR.GetTile(new Vector3Int(mx, my, 0))); stairLeft.SetTile(new Vector3Int(x * roomSize.x + mx, y * roomSize.y + my, 0), thisStairL.GetTile(new Vector3Int(mx, my, 0))); zombiePaths[x, y][mx, my] = roomPaths.HasTile(new Vector3Int(mx, my, 0)); } } roomCounter++; } } } walls.CompressBounds(); platform.CompressBounds(); stairRight.CompressBounds(); stairLeft.CompressBounds(); transform.position = new Vector3(-startPos.x * roomSize.x, -startPos.y * roomSize.y, 0); GameObject spawnedPlayer = Instantiate(player, new Vector3(roomSize.x * 0.5f, roomSize.y * 0.2f), Quaternion.identity); GameObject spawnedZombie = Instantiate(zombie, new Vector3((currentPos.x - (Width * 0.5f) + 0.5f) * roomSize.x, (currentPos.y - (Height * 0.5f) + 0.2f) * roomSize.y), Quaternion.identity); spawnedZombie.GetComponent <zombiescript>().player = spawnedPlayer; spawnedZombie.GetComponent <zombiescript>().mapGenerator = GetComponent <mapGenerator>(); spawnedZombie.GetComponent <zombiescript>().pathfinding = GetComponent <pathfinding>(); /* * Debug.Log(roomCounter); * //Debug.Log("Start: " + startPos + ", End: " + currentPos); * List<Vector2Int> path = GetComponent<pathfinding>().findMacroPath(startPos, currentPos, mapPaths); * Vector2Int position = startPos; * path.Reverse(); * foreach (Vector2Int point in path) * { * //Debug.Log(point); * Debug.DrawLine(new Vector3(position.x - 249.5f, position.y - 249.5f) * 10, new Vector3(point.x - 249.5f, point.y - 249.5f) * 10, Color.red, 10000f); * position = point; * } */ }