public bool InitPathmap() { string[] lines = System.IO.File.ReadAllLines("Assets/Data/Map.txt"); for (int y = 0; y < lines.Length; y++) { char[] line = lines[y].ToCharArray(); for (int x = 0; x < line.Length; x++) { PathmapTile tile = new PathmapTile(); tile.posX = x; tile.posY = -y; tiles.Add(tile); switch (line[x]) { case 'x': tile.blocking = true; break; case 'p': playerStartPos = new Vector2(tile.posX, tile.posY); break; case 'g': ghostStartPos = new Vector2(tile.posX, tile.posY); break; case 'G': ghostExitPos = new Vector2Int(tile.posX, tile.posY); break; case '.': SmallDot smallDot = GameObject.Instantiate(smallDotPrefab).GetComponent <SmallDot>(); smallDot.transform.SetParent(smallDotGroup.transform); smallDot.SetPosition(new Vector2(x * MapManager.Get().tileSize, -y * MapManager.Get().tileSize)); smallDot.OnCollected += OnItemColleted; smallDots.Add(smallDot); dotCount++; break; case 'o': PowerDot powerDot = GameObject.Instantiate(powerDotPrefab).GetComponent <PowerDot>(); powerDot.transform.SetParent(powerDotGroup.transform); powerDot.SetPosition(new Vector2(x * MapManager.Get().tileSize, -y * MapManager.Get().tileSize)); powerDot.OnCollected += OnItemColleted; powerDots.Add(powerDot); dotCount++; break; } } } canSpawnCherry = true; return(true); }
public bool InitDots() { string[] lines = System.IO.File.ReadAllLines("Assets/Data/map.txt"); for (int y = 0; y < lines.Length; y++) { char[] line = lines[y].ToCharArray(); for (int x = 0; x < line.Length; x++) { if (line[x] == '.') { SmallDot dot = GameObject.Instantiate(SmallDotPrefab).GetComponent <SmallDot>(); dot.name = string.Format("SmallDot X= {0:0} Y= {1:0}", x, y); dot.SetPosition(new Vector2((x - (line.Length / 2)) * 22 + 11, (-y + (lines.Length / 2)) * 22)); dotCount++; } } } return(true); }