public void DestroySquares(dmBlock block) { foreach (GameObject squareInstance in block.squareList) { Destroy(squareInstance); } }
public void FallGround(dmBlock block) { for (int i = 0; i < block.bindBase.squareCoordList.Count; i++) { squareMap.Add(nowBlockPos + block.bindBase.squareCoordList[i], block.squareList[i]); block.squareList[i].GetComponentInChildren <Image>().color = Color.gray; } }
public void PutInBlock(dmBlock block) { nowControlBlock = block; blockBuilder.nowBlock = null; foreach (GameObject square in block.squareList) { square.transform.SetParent(transform); } MoveBlockTo(block, initPos); }
public bool CheckCollision(dmBlock block, Vector2 targetPos) { foreach (Vector2 squareCoord in block.bindBase.squareCoordList) { Vector2 squarePos = squareCoord + targetPos; if (squarePos.y >= areaSize.y || squarePos.x < 0 || squarePos.x >= areaSize.x) { return(true); } if (squareMap.ContainsKey(squarePos)) { return(true); } } return(false); }
public void MoveBlockTo(dmBlock onMoveBlock, Vector2 targetPos) { if (CheckCollision(onMoveBlock, targetPos)) { runFlag = false; return; } for (int i = 0; i < onMoveBlock.bindBase.squareCoordList.Count; i++) { Vector2 squareCoord = targetPos + onMoveBlock.bindBase.squareCoordList[i]; onMoveBlock.squareList[i].transform.localPosition = AreaPos2Local(squareCoord); onMoveBlock.squareList[i].SetActive(squareCoord.y >= 0); } nowBlockPos = targetPos; }
public void BuildRandomBlock() { if (nowBlock != null) { DestroySquares(nowBlock); } dmBlockBase inBuildingBlock = blockBaseList[Random.Range(0, blockBaseList.Count)]; nowBlock = new dmBlock(); nowBlock.InitBlock(inBuildingBlock); foreach (Vector2 vec in nowBlock.bindBase.squareCoordList) { GameObject newSquare = Instantiate(squarePrefab); newSquare.transform.SetParent(transform); newSquare.GetComponent <RectTransform>().sizeDelta = squareSize; newSquare.transform.localPosition = genePos + new Vector2(squareSize.x * vec.x * 2.5f, -squareSize.x * vec.y * 2.5f); Debug.Log(vec); nowBlock.squareList.Add(newSquare); } }