// contsructor public Tetramino(TetraType type, Point loc, PieceState state) { cType = type; Loc = loc; cState = state; this.FillTetra(); }
public void StartGame() { foreach (Transform child in transform) { Destroy(child.gameObject); } gridBlocks = new GameObject[gridSizeX, gridHeight + 2, gridSizeZ]; currentCoords = new Vector3Int[4]; currentBlocks = new GameObject[4]; previewCoords = new Vector3Int[4]; previewBlocks = new GameObject[4]; gridOffset = -0.5f * new Vector3(gridSizeX, 0, gridSizeZ) + new Vector3(0.5f, 0, 0.5f); tetraCubeQueue = new List <TetraType>(); heldType = TetraType.None; UpdateMaterial(); for (int i = 0; i < gridSizeX; i++) { for (int j = 0; j < gridSizeZ; j++) { GameObject go = Instantiate(cube, transform); go.transform.position = new Vector3(i, -1, j) + gridOffset; go.GetComponent <Renderer>().material = matBase; } } topLine.SetPositions(new Vector3[] { new Vector3(gridSizeX / 2, gridHeight - 0.5f, gridSizeZ / 2), new Vector3(-gridSizeX / 2, gridHeight - 0.5f, gridSizeZ / 2), new Vector3(-gridSizeX / 2, gridHeight - 0.5f, -gridSizeZ / 2), new Vector3(gridSizeX / 2, gridHeight - 0.5f, -gridSizeZ / 2), }); NewTetraCube(false); score = 0; inGame = true; menuUI.SetActive(false); gameUI.SetActive(true); // Progression level = 0; exp = 0; combo = 0; UpdateLevelUI(); comboUI.SetActive(false); }
private void NewTetraCube(bool fromHeld) { if (tetraCubeQueue.Count == 0) { // Populate tetraCubeQueue = new List <TetraType>() { TetraType.I, TetraType.O, TetraType.L, TetraType.T, TetraType.N, TetraType.TL, TetraType.TR, TetraType.A, }; for (int i = 0; i < tetraCubeQueue.Count; i++) { TetraType temp = tetraCubeQueue[i]; int randomIndex = UnityEngine.Random.Range(i, tetraCubeQueue.Count); tetraCubeQueue[i] = tetraCubeQueue[randomIndex]; tetraCubeQueue[randomIndex] = temp; } } // if from held tetraCube if (fromHeld) { if (hasHeld) { return; } TetraType temp = currentType; currentType = heldType; heldType = temp; foreach (GameObject block in currentBlocks) { Destroy(block); } hasHeld = true; } heldText.text = heldType.ToString(); // Pop from queue if (!fromHeld || currentType == TetraType.None) { currentType = tetraCubeQueue[0]; tetraCubeQueue.RemoveAt(0); hasHeld = false; } int l = gridHeight + 1; Material m = mats[(int)currentType]; int cx = gridSizeX / 2; int cz = gridSizeZ / 2; switch (currentType) { case TetraType.I: currentCoords[2] = new Vector3Int(cx - 2, l, cz); currentCoords[1] = new Vector3Int(cx - 1, l, cz); currentCoords[0] = new Vector3Int(cx + 0, l, cz); currentCoords[3] = new Vector3Int(cx + 1, l, cz); break; case TetraType.O: currentCoords[0] = new Vector3Int(cx + 0, l, cz + 0); currentCoords[1] = new Vector3Int(cx + 0, l, cz - 1); currentCoords[2] = new Vector3Int(cx - 1, l, cz + 0); currentCoords[3] = new Vector3Int(cx - 1, l, cz - 1); break; case TetraType.L: currentCoords[1] = new Vector3Int(cx - 1, l, cz + 0); currentCoords[0] = new Vector3Int(cx + 0, l, cz + 0); currentCoords[2] = new Vector3Int(cx + 1, l, cz + 0); currentCoords[3] = new Vector3Int(cx - 1, l, cz - 1); break; case TetraType.T: currentCoords[1] = new Vector3Int(cx - 1, l, cz + 0); currentCoords[0] = new Vector3Int(cx + 0, l, cz + 0); currentCoords[2] = new Vector3Int(cx + 1, l, cz + 0); currentCoords[3] = new Vector3Int(cx + 0, l, cz - 1); break; case TetraType.N: currentCoords[1] = new Vector3Int(cx - 1, l, cz - 1); currentCoords[0] = new Vector3Int(cx + 0, l, cz + 0); currentCoords[2] = new Vector3Int(cx + 1, l, cz + 0); currentCoords[3] = new Vector3Int(cx + 0, l, cz - 1); break; case TetraType.TL: currentCoords[1] = new Vector3Int(cx - 1, l, cz + 0); currentCoords[0] = new Vector3Int(cx + 0, l, cz + 0); currentCoords[2] = new Vector3Int(cx + 0, l, cz - 1); currentCoords[3] = new Vector3Int(cx + 0, l - 1, cz - 1); break; case TetraType.TR: currentCoords[1] = new Vector3Int(cx - 1, l, cz + 0); currentCoords[0] = new Vector3Int(cx + 0, l, cz + 0); currentCoords[2] = new Vector3Int(cx + 0, l, cz - 1); currentCoords[3] = new Vector3Int(cx - 1, l - 1, cz + 0); break; case TetraType.A: currentCoords[1] = new Vector3Int(cx - 1, l, cz + 0); currentCoords[0] = new Vector3Int(cx + 0, l, cz + 0); currentCoords[2] = new Vector3Int(cx + 0, l, cz - 1); currentCoords[3] = new Vector3Int(cx + 0, l - 1, cz + 0); break; default: throw new Exception("Missing Type in NewTetraCube"); } for (int i = 0; i < currentCoords.Length; i++) { currentBlocks[i] = Instantiate(cube, transform); currentBlocks[i].transform.position = currentCoords[i] + gridOffset; currentBlocks[i].GetComponent <Renderer>().material = m; } Color pivotColor = 0.8f * m.color; currentBlocks[0].GetComponent <Renderer>().material.SetColor("_Color", pivotColor); UpdatePreview(); }