//Finds all of the empty blocks and fills them with a new randomized block void initEmptyBlocks() { //Iterate through the 2-layer array here for (int j = 0; j < colorBlockArray.GetLength(0); j++) { for (int i = 0; i < colorBlockArray.GetLength(1); i++) { if (!(colorBlockArray[j, i] != null)) { //dropBlock(Random.Range(0,dropBlockArray.Length-1), true) //ColorBlock.randomizeBlock (); colorBlock block = (colorBlock)Instantiate(ColorBlock); colorBlockArray [j, i] = block as colorBlock; blockSetIncrement(); colorBlockArray [j, i].setBlockColor(blockSet); blockSetIncrement(); //colorBlockArray [j, i].randomizeBlock(); colorBlockArray [j, i].transform.position = getArrayLocationVector3(j, i); colorBlockArray [j, i].setVecPos(getArrayLocationVector3(j, i)); colorBlockArray [j, i].setXY(j, i); colorBlockArray [j, i].setScoreCombo(false); //RemovalBlocks are the graphical removing effect. removalBlock rBlock = (removalBlock)Instantiate(RemovalSphere); rBlock.transform.position = colorBlockArray [j, i].transform.position; } } } }
void swapLeft(int x, int y) { if (x - 1 >= 0) { //Do a temp based swap colorBlock temp = colorBlockArray[x, y]; colorBlockArray[x, y] = colorBlockArray[x - 1, y]; colorBlockArray[x - 1, y] = temp; colorBlockArray[x, y].setVecPos(getArrayLocationVector3(x, y)); colorBlockArray[x, y].setXY(x, y); colorBlockArray[x, y].transform.position = getArrayLocationVector3(x, y); colorBlockArray[x - 1, y].setVecPos(getArrayLocationVector3(x - 1, y)); colorBlockArray[x - 1, y].setXY(x - 1, y); refreshColorBlock(x, y); refreshColorBlock(x - 1, y); } left = false; }
void swapRight(int x, int y) { if (colorBlockArray.GetLength(0) - 1 >= x + 1) { //Do a temp based swap colorBlock temp = colorBlockArray[x, y]; colorBlockArray[x, y] = colorBlockArray[x + 1, y]; colorBlockArray[x + 1, y] = temp; colorBlockArray[x, y].setVecPos(getArrayLocationVector3(x, y)); colorBlockArray[x, y].setXY(x, y); colorBlockArray[x, y].transform.position = getArrayLocationVector3(x, y); colorBlockArray[x + 1, y].setVecPos(getArrayLocationVector3(x + 1, y)); colorBlockArray[x + 1, y].setXY(x + 1, y); refreshColorBlock(x, y); refreshColorBlock(x + 1, y); } right = false; }
void swapDown(int x, int y) { if (y - 1 >= 0) { //Do a temp based swap colorBlock temp = colorBlockArray[x, y]; colorBlockArray[x, y] = colorBlockArray[x, y - 1]; colorBlockArray[x, y - 1] = temp; colorBlockArray[x, y].setVecPos(getArrayLocationVector3(x, y)); colorBlockArray[x, y].setXY(x, y); colorBlockArray[x, y].transform.position = getArrayLocationVector3(x, y); colorBlockArray[x, y - 1].setVecPos(getArrayLocationVector3(x, y - 1)); colorBlockArray[x, y - 1].setXY(x, y - 1); refreshColorBlock(x, y); refreshColorBlock(x, y - 1); } down = false; }
//End Cursor Stuff /* * Swaps * These methods swap a sphere with another sphere. */ void swapUp(int x, int y) //We take the spot we are given and move it up one. { if (colorBlockArray.GetLength(1) - 1 >= y + 1) //If we are in our Array //Do a temp based swap { colorBlock temp = colorBlockArray[x, y]; colorBlockArray[x, y] = colorBlockArray[x, y + 1]; colorBlockArray[x, y + 1] = temp; colorBlockArray[x, y].setVecPos(getArrayLocationVector3(x, y)); colorBlockArray[x, y].setXY(x, y); colorBlockArray[x, y].transform.position = getArrayLocationVector3(x, y); colorBlockArray[x, y + 1].setVecPos(getArrayLocationVector3(x, y + 1)); colorBlockArray[x, y + 1].setXY(x, y + 1); refreshColorBlock(x, y); refreshColorBlock(x, y + 1); } up = false; }
//End Selected Block Stuff //Fills the starting block array full to the brim with blocks of randomly assigned colors. void initBlocksRandomly() { //Iterate through the 2-layer array here for (int j = 0; j < colorBlockArray.GetLength(0); j++) { for (int i = 0; i < colorBlockArray.GetLength(1); i++) { //dropBlock(Random.Range(0,dropBlockArray.Length-1), true) //ColorBlock.randomizeBlock (); colorBlock block = (colorBlock)Instantiate(ColorBlock); block.randomizeBlock(); block.transform.position = getArrayLocationVector3(j, i); block.setVecPos(getArrayLocationVector3(j, i)); blockSetIncrement(); block.setBlockColor(blockSet); blockSetIncrement(); colorBlockArray [j, i] = block as colorBlock; colorBlockArray[j, i].setXY(j, i); colorBlockArray [j, i].setScoreCombo(false); } } }
//Maintains the touch input system. Everything having to do with that loop is here, more or less. void touchCheck() { if (allowTouch) { if (Input.touchCount > 0) { touchesOld = new GameObject[touchList.Count]; touchList.CopyTo(touchesOld); touchList.Clear(); //Here is where we check each individual touch and see what it is doing. foreach (Touch touch in Input.touches) { Ray ray = camera.ScreenPointToRay(touch.position); if (Physics.Raycast(ray, out hit, touchInputMask)) //If we send out a ray and it hits something in the touchInputMask... //GameObject recipient = hit.transform.gameObject; //touchList.Add (recipient); { if (touch.phase == TouchPhase.Began) { if (!(selected != null)) { //WE HIT SOMETHING! Start the timer. currentState = State.Dragging; //Also, take note of the thing that we found. colorBlock foundthing = hit.transform.GetComponent <colorBlock>(); selected = foundthing; } } else if (touch.phase == TouchPhase.Ended) { //recipient.SendMessage ("OnTouchUp", hit.point, SendMessageOptions.DontRequireReceiver); currentState = State.Matching; //selected.transform.position = selected.gameObject.GetComponent<colorBlock>().gridPos; if (selected != null) { selected.SendMessage("releaseBlock", SendMessageOptions.DontRequireReceiver); selected = null; //print("released"); stepIndex = 1; } } else if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) { //recipient.SendMessage ("OnTouchStay", hit.point, SendMessageOptions.DontRequireReceiver); } else if (touch.phase == TouchPhase.Canceled) { //recipient.SendMessage ("OnTouchExit", hit.point, SendMessageOptions.DontRequireReceiver); currentState = State.Matching; selected.SendMessage("releaseBlock", SendMessageOptions.DontRequireReceiver); //print("released"); selected = null; stepIndex = 1; } else if (touch.phase == TouchPhase.Ended) { currentState = State.Matching; selected.SendMessage("releaseBlock", SendMessageOptions.DontRequireReceiver); selected = null; stepIndex = 1; } } } } //If we have something selected, move it. if (selected != null) { Vector3 curPosition = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); selected.transform.position = new Vector3(curPosition.x, curPosition.y, selected.transform.position.z); swapDistCheck(); } } }