Level boardState; //Row, Column // East col+, North row+ /* 0 = empty * 1 = wall * 2 = player * 3 = mimic * 4 = mirror * 10 = goal */ // Use this for initialization void Start() { firstStart = false; //load level using Melody's I/O boardState = IOScript.ParseLevel(levelName); // TODO: Below the way we get the index is DISGUSTING, this whole shitshow needs refactored levelNum = CreateLevelSelect.levelList.IndexOf(levelName); LoggingManager.instance.RecordLevelStart(levelNum, levelName); mapOrigin = new Vector2(-boardState.cols / 2.0f, -boardState.rows / 2.0f); mainCamera.orthographicSize = boardState.rows / 2.0f + 1; tutorial.text = boardState.tutorial; tutorial.enabled = true; if (levelNum == 0) { tutorial1.SetActive(true); } else if (levelNum == 5) { tutorial6.SetActive(true); } int buttonCount = 0; //instantiate lasers based on parsed lasers if (boardState.lasers != null) { foreach (Laser la in boardState.lasers) { LaserScript l = GameObject.Instantiate(laser); l.makeLaser(la, mapOrigin); laserList.Add(l); } } //instantiate items based on board for (int i = 0; i < boardState.rows; i++) { for (int j = 0; j < boardState.cols; j++) { if (boardState.board[i, j] == 1) { //wall GameObject w; if (i == 0 || boardState.board[i - 1, j] != 1) { w = GameObject.Instantiate(frontWall); } else { w = GameObject.Instantiate(wall); } w.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); } else if (boardState.board[i, j] >= 10 && boardState.board[i, j] < 20) { // goal GoalScript c = GameObject.Instantiate(goal); c.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); goalAtCoords.Add(new coord(i, j), c); goalCoords.Add(new coord(i, j)); } else if (boardState.board[i, j] >= 20 && boardState.board[i, j] < 30) { // swap GameObject c = GameObject.Instantiate(swap); c.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); swapCoords.Add(new coord(i, j)); } else if (boardState.board[i, j] >= 30 && boardState.board[i, j] < 40) { // button ButtonToggleScript c = GameObject.Instantiate(button); c.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); c.laser = laserList[boardState.buttons[buttonCount]]; c.InitButton(); buttonCoords.Add(new coord(i, j), c); buttonCount++; } else if (boardState.board[i, j] >= 50 && boardState.board[i, j] < 60) { // portal GameObject p = GameObject.Instantiate(portal); p.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); portalCoords.Add(new coord(i, j)); } else { // ground GameObject g = GameObject.Instantiate(ground); g.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y, 0); } if (boardState.board[i, j] % 10 == 2) { // player player = GameObject.Instantiate(player); player.SetCoords(j, i); player.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y + player.yOffset, -0.2f); moveables.Add(player); } else if (boardState.board[i, j] % 10 == 3) { // mimic MimicScript m = GameObject.Instantiate(mimic); m.SetCoords(j, i); m.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y + m.yOffset, -0.2f); moveables.Add(m); } else if (boardState.board[i, j] % 10 == 4) { // mirror MirrorScript m = GameObject.Instantiate(mirror); m.SetCoords(j, i); m.transform.position = new Vector3(j + mapOrigin.x, i + mapOrigin.y + m.yOffset, -0.2f); moveables.Add(m); } } } if (boardState.portals != null) { for (int i = 0; i < boardState.portals.Length; i++) { portalMap.Add(portalCoords[i], portalCoords[boardState.portals[i]]); } } }
// Use this for initialization void Start() { // initialize grid if (loadedLevel && levelName != null) { level = IOScript.ParseLevel(levelName); int b = 0; for (int r = 0; r < level.rows; r++) { for (int c = 0; c < level.cols; c++) { if (level.board[r, c] / 10 == 3) { buttonList.Add(new coord(r, c)); lasers.Add(new coord(r, c), level.lasers[level.buttons[b]]); b++; } if (level.board[r, c] / 10 == 5) { portalList.Add(new coord(r, c)); } } } for (int p = 0; p < level.portals.GetLength(0); p++) { portalMapping.Add(portalList[p], portalList[level.portals[p]]); } } else { level.board = new int[level.rows, level.cols]; fillOutline(level); } width *= canvas.pixelRect.width; sidebarWidth = canvas.pixelRect.width - width; height *= canvas.pixelRect.height; clickTile = toggleWall; // creates entire view createAndPositionSquares(level); // position sidebar buttons saveAsButton.rectTransform.anchoredPosition = new Vector2((width + sidebarWidth / 2f), sidebarWidth / 4f); saveAsButton.rectTransform.sizeDelta = new Vector2(sidebarWidth, sidebarWidth / 2f); saveAsButton.rectTransform.localScale = Vector2.one; saveButton.rectTransform.anchoredPosition = new Vector2((width + sidebarWidth / 2f), 3f * sidebarWidth / 4f); saveButton.rectTransform.sizeDelta = new Vector2(sidebarWidth, sidebarWidth / 2f); saveButton.rectTransform.localScale = Vector2.one; resizeButton.rectTransform.anchoredPosition = new Vector2((width + sidebarWidth / 2f), 5f * sidebarWidth / 4f); resizeButton.rectTransform.sizeDelta = new Vector2(sidebarWidth, sidebarWidth / 2f); resizeButton.rectTransform.localScale = Vector2.one; for (int i = 0; i < clickSetters.Count; i++) { RawImage button = Instantiate(this.sidebarPiece); button.transform.parent = this.canvas.transform; positionSidebarPiece(button, clickSetters[i], i, clickSetters.Count, height, sidebarWidth * 3f / 2f); } /*sidebar.rectTransform.anchoredPosition = new Vector2((width + sidebarWidth / 2f), 2.35f * sidebarWidth); * sidebar.rectTransform.sizeDelta = new Vector2(sidebarWidth, height - (sidebarWidth * 3f / 2f) - padding); * sidebar.rectTransform.localScale = Vector2.one;*/ setNamePopUpVisible(false); setSizePopUpVisible(false); }