//SceneManager. void createLump(int x, int y, byte color) { //create the lump _lump lump = new _lump(x, y, color); //create the flower list and add this new flower lump.obj = (GameObject)Instantiate(flowerPrefab[(int)color]); //move it to the right spot //lump.flowers.transform.Rotate (90, 0, 0); if (color == flowerPrefab.Count - 1) { lump.obj.transform.Rotate(0, 0, 0); lump.obj.transform.localPosition = new Vector3((x * 2) - 5, 0, (y * 2) - 5); } else { lump.obj.transform.localPosition = new Vector3((x * 2) - 5, 0.38f, (y * 2) - 5); } lump.plane = (GameObject)Instantiate(planePrefab); lump.plane.transform.position = new Vector3((x * 2) - 5, 0.002f, (y * 2) - 5); lump.plane.GetComponent <Renderer>().enabled = false; lump.movable = (lump.color < flowerPrefab.Count - 1); //add the lump to the list lumps.Add(lump); }
string endClick() { if (!clicked) { return(""); } clicked = false; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { _lump l = lumps.Find(_l => _l.obj.transform == hit.transform); if (l.x != -1 && l.x == startlump.x && l.y == startlump.y) { return("click"); } } int dx = Mathf.RoundToInt(Input.mousePosition.x - startclickf.x); int dy = Mathf.RoundToInt(Input.mousePosition.y - startclickf.y); if (dx == dy || Mathf.Abs(dx) + Mathf.Abs(dy) < 30) { return(""); } if (Mathf.Abs(dx) > Mathf.Abs(dy)) { if (dx < 0) { return("left"); } else { return("right"); } } else { if (dy < 0) { return("down"); } else { return("up"); } } }
void startClick() { clicked = true; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; startclickf = new Vector2(Input.mousePosition.x, Input.mousePosition.y); if (Physics.Raycast(ray, out hit, 100)) { startlump = lumps.Find(_l => _l.obj.transform == hit.transform); } else { startlump = new _lump(-1, -1, 0); } }
void checkBuddies(_lump l_start, bool highlight = true) { countLumpsSelected++; if (highlight) { l_start.plane.transform.position = new Vector3((l_start.x * 2) - 5, 0.002f, (l_start.y * 2) - 5); l_start.plane.GetComponent <Renderer> ().enabled = true; } l_start.highlighted = true; //check left _lump l_next = lumps.Find(_l => (_l.x == (l_start.x - 1) && _l.y == l_start.y)); if (l_next != null && l_next.color == l_start.color && l_next.highlighted == false) { checkBuddies(l_next, highlight); } //check right l_next = lumps.Find(_l => (_l.x == (l_start.x + 1) && _l.y == l_start.y)); if (l_next != null && l_next.color == l_start.color && l_next.highlighted == false) { checkBuddies(l_next, highlight); } //check up l_next = lumps.Find(_l => (_l.x == l_start.x && _l.y == (l_start.y - 1))); if (l_next != null && l_next.color == l_start.color && l_next.highlighted == false) { checkBuddies(l_next, highlight); } //check down l_next = lumps.Find(_l => (_l.x == l_start.x && _l.y == (l_start.y + 1))); if (l_next != null && l_next.color == l_start.color && l_next.highlighted == false) { checkBuddies(l_next, highlight); } }
void shiftLumps(int shiftX, int shiftY) { if (highlighted) { removeHighlights(); } int xStart = (shiftX == -1 ? 1 : (shiftX == 1 ? 4 : 5)); int yStart = (shiftY == -1 ? 1 : (shiftY == 1 ? 4 : 5)); int xInc = (shiftX == -1 ? -1 : 1); int yInc = (shiftY == -1 ? -1 : 1); for (int x = xStart; x > -1 && x < 6; x -= xInc) { for (int y = yStart; y > -1 && y < 6; y -= yInc) { //nothing assinged to this square? simply continue _lump l = lumps.Find(delegate(_lump _l) { return(_l.x == x && _l.y == y); }); if (l == null || !l.movable) { continue; } int subX = x, subY = y; if (shiftX != 0) { for (subX = x + shiftX; subX > -1 && subX < 6; subX += xInc) { if (lumps.Find(delegate(_lump _l) { return(_l.x == subX && _l.y == y); }) != null) { break; } } subX -= xInc; } if (shiftY != 0) { for (subY = y + shiftY; subY > -1 && subY < 6; subY += yInc) { if (lumps.Find(delegate(_lump _l) { return(_l.x == x && _l.y == subY); }) != null) { break; } } subY -= yInc; } l.x = subX; l.y = subY; _mover m = new _mover(); m.from = new Vector3((x * 2) - 5, 0.38f, (y * 2) - 5); m.to = new Vector3((subX * 2) - 5, 0.38f, (subY * 2) - 5); m.lump = l; if (Vector3.Distance(m.from, m.to) > .01) { movement.Add(m); } lerpDt = 0; if (!(x == subX && y == subY)) { moving = true; } } } if (movement.Count > 0) { moveSound.Play(); moveText.text = "Moves\n" + --moves; setSun(1 - (float)moves / (float)_level._l.moves); if (moves == 0 && !canSellAnything()) { showGameover(2); return; } if (moves == 1 && bank < _level._l.goal && !shownAd) { adMenu.SetActive(true); } } }