/// <summary> /// Updates the grid with the tetromino position /// </summary> /// <param name="tetromino">The tetromino to update</param> public void UpdateGrid(Tetromino tetromino) { for (int y = 0; y < GridHeight; y++) { for (int x = 0; x < GridWidth; x++) { if (Grid[x, y] != null) { if (Grid[x, y].parent == tetromino.transform) { Grid[x, y] = null; } } } } foreach (Transform mino in tetromino.transform) { Vector2 pos = Round(mino.position); if (pos.y < GridHeight) { Grid[(int)pos.x, (int)pos.y] = mino; } } }
public bool CheckIfNextRotationIsPossible(Tetromino tetromino) { Vector2 pos = Vector2.zero; tetromino.RotateTetromino(); //here it checks for each mino inside tetromino and check every position foreach (Transform mino in tetromino.transform) { pos = tetromino.transform.localPosition + mino.localPosition; if (!CheckIsInsideGrid(pos)) { tetromino.UndoRotateTetromino(); return(false); } //checks if theres already a mino on that position and if if (GetTransformAtGridPosition(pos) != null && GetTransformAtGridPosition(pos).parent != tetromino.transform) { tetromino.UndoRotateTetromino(); return(false); } } tetromino.UndoRotateTetromino(); return(true); }
[TestMethod] public void RemoveOneFullRow() { AddTestData(); board.RemoveFullRows(0, 4); TestUtil.CheckBoardState(board, new string[] { ".....", "....#", ".#.##", ".####" }); Tetromino tetromino = new Tetromino(1, board); board.AddTetromino(tetromino); TestUtil.CheckBoardState(board, new string[] { "#....", "#...#", "##.##", "#####" }); board.RemoveFullRows(0, 4); TestUtil.CheckBoardState(board, new string[] { ".....", "#....", "#...#", "##.##" }); }
public void UpdateGrid(Tetromino tetromino) { for (int y = 0; y < gridHeight; y++) { for (int x = 0; x < gridWidth; x++) { for (int z = 0; z < gridWidth; z++) { if (grid [x, y, z] != null) { if (grid [x, y, z].parent == tetromino.transform) { grid [x, y, z] = null; } } } } } foreach (Transform mino in tetromino.transform) { Vector3 pos = Round(mino.position); if (pos.y < gridHeight) { grid [(int)pos.x, (int)pos.y, (int)pos.z] = mino; } } }
void ApplyTetromino() { if (tetr != null) { List <IntPair> list = tetr.GetTileCoordinates(); if (tetr.isValid()) { foreach (IntPair p in list) { GameBoard.set(p.x, p.y, 1); } List <int> rows = GameBoard.getCompletedRows(); if (rows.Count > 0) { GameBoard.deleteRows(rows); } piecesLeft--; if (piecesLeft > 0) { tetr = new Tetromino(G_WIDTH, GameBoard); } else { NeedyModule.HandlePass(); tetr = null; } UpdateGrid(); } } }
} // 함수 끝 public void UpdateGrid(Tetromino tetromino) // 전체 공간 계산(남은공간) { for (int location_y = 0; location_y < gridHeight; ++location_y) { for (int location_x = 0; location_x < gridWidth; ++location_x) { if (grid[location_x, location_y] != null) { if (grid[location_x, location_y].parent == tetromino.transform) { grid[location_x, location_y] = null; } } } } foreach (Transform mino in tetromino.transform) // 블록이 차지하고 있는 공간 계산 { Vector2 pos = Round(mino.position); if (pos.y < gridHeight) { grid[(int)pos.x, (int)pos.y] = mino; } } } // 함수 끝
void SpawnPiece() { if (randomPieceBag.Count == 0) { InitRandomBag(); } int index = Random.Range(0, randomPieceBag.Count); int selectedPiece = randomPieceBag[index]; randomPieceBag.RemoveAt(index); if (randomPieceBag.Count == 0) { InitRandomBag(); } movingTetromino = Instantiate(piecesToSpawn[selectedPiece], transform.position + spawnPoint, Quaternion.identity).GetComponent <Tetromino>(); if (!movingTetromino.ValidPosition()) { dead = true; movingTetromino = null; Debug.Log("You lose!"); } }
public override Tetromino Build() { Tetromino mino = new Tetromino(); for (uint y = 0; y < 4; ++y) { for (uint x = 0; x < 4; ++x) { if (Textures[y, x] != null) { mino.Blocks.Add(new Block.Block { Transform = new Transform { Position = new Vector3 { X = x, Y = y, Z = Layers.PieceLayer } }, Size = new Vector3(1, 1, 1), Texture = Textures[y, x] }); } } } return(mino); }
// Generates a random Tetromino for the queue private Tetromino generateTetromino() { Tetromino t; switch (generationPolicy) { case PieceGenerationPolicy.REROLL: t = randomTetromino(); while(reroll < maxReroll && (t.Equals(previous) || tetrominoQueue.Contains(t))) { t.Destroy(); t = randomTetromino(); reroll++; } previous = t; reroll = 0; break; case PieceGenerationPolicy.RANDOMBAG: if (bag.Count == 0) { refillBag(); } t = pullFromBag(); break; default: t = randomTetromino(); break; } t.setGhostActive(true); return t; }
// Retreives a piece at random from the "bag" when using the RANDOMBAG policy private Tetromino pullFromBag() { int idx = Random.Range(0, bag.Count); Tetromino t = Instantiate(bag[idx]); bag.RemoveAt(idx); return t; }
public Vector2 GetHardDropPosition(Tetromino tetromino) { int offset = 0; for (int i = 0; i < tetromino.transform.position.y; i++) { bool possible = true; foreach (Transform mino in tetromino.transform) { Transform currMino = GetTransformAtPosition(new Vector2(mino.position.x, mino.position.y - i)); if ((currMino != null && currMino.parent != tetromino.transform) || mino.position.y - i <= 0) { possible = false; break; } } if (possible) { offset = i; } else { break; } } return(new Vector2(tetromino.transform.position.x, tetromino.transform.position.y - offset)); }
public void UpdateGhost() { if (moving && !isGhost) { if (ghost == null) { ghost = Instantiate(this, transform.position, transform.rotation); ghost.isGhost = true; foreach (Transform child in ghost.transform) { child.GetComponent <SpriteRenderer>().color = new Color(1f, 1f, 1f, 0.3f); } } ghost.transform.position = transform.position; ghost.transform.rotation = transform.rotation; Vector3 oldPos = ghost.transform.position; while (Playfield.CheckPos(ghost.transform)) { oldPos = ghost.transform.position; ghost.transform.position += new Vector3(0, -1, 0); } ghost.transform.position = oldPos; foreach (Transform mino in ghost.transform) { mino.rotation = Quaternion.identity; } } }
public void LeftMovement(Tetromino tetromino) { if (movedImmediateHorizontal) { if (buttonDownWaitTimer < buttonDownWaitMax) { buttonDownWaitTimer += Time.deltaTime; return; } if (horizontalTimer < continuousHorizontalSpeed) { horizontalTimer += Time.deltaTime; return; } } if (!movedImmediateHorizontal) { movedImmediateHorizontal = true; } horizontalTimer = 0; tetromino.transform.position += new Vector3(-1, 0, 0);//двигаем влево на 1 позицию if (CheckIsValidPosition()) { game.UpdateGrid(this); } else { tetromino.transform.position += new Vector3(1, 0, 0);// если занято ,возращаем прежнее положение } }
public bool NextMoveIsPossible(Tetromino tetromino, Vector2 nextMove) { Vector2 pos = Vector2.zero; //here it checks for each mino inside tetromino and check every position foreach (Transform mino in tetromino.transform) { // for each mino inside of the tetromino pos = Round(tetromino.transform.localPosition + mino.localPosition) + nextMove; //checks next move and verifies every mino pos //Debug.Log("pos" + pos); //checks if every mino is inside of the playerGrid if (!CheckIsInsideGrid(pos)) { return(false); } //checks if theres already a mino on that position and if if (GetTransformAtGridPosition(pos) != null && GetTransformAtGridPosition(pos).parent != tetromino.transform) { return(false); } } return(true); }
public void UpdateGrid(Tetromino _tetromino) { int x, y; for (y = 0; y < _gridHeight; ++y) { for (x = 0; x < _gridWidth; ++x) { if (_grid[x, y] != null) { if (_grid[x, y].parent == _tetromino.transform) { _grid[x, y] = null; } } } } foreach (Transform _mino in _tetromino.transform) { Vector2 _position = Round(_mino.position); if (_position.y < _gridHeight) { _grid[(int)_position.x, (int)_position.y] = _mino; } } }
public Tetromino Next() { var current = next; next = baseGenerator.Next(); return(current); }
public void UpdateGrid(Tetromino tet) { for (int y = 0; y < m_GridHeight; ++y) { for (int x = 0; x < m_GridWidth; ++x) { if (grid[x, y] != null) { if (grid[x, y].parent == tet.transform) { grid[x, y] = null; } } } } foreach (Transform mino in tet.transform) { if (mino != tet.transform.GetChild(4)) { Vector2 pos = RoundVec2(mino.position); if (pos.y < m_GridHeight) { grid[(int)pos.x, (int)pos.y] = mino; } } } }
public Bloc(Tetromino tetromino, Position localPosition, bool isGhost) { this.Tetromino = tetromino; this.LocalPosition = localPosition; this.LastRegisteredPosition = Position.Invalid; this.IsGhost = isGhost; }
/// <summary> /// Perform NES rotaiton /// </summary> /// <param name="piece">Current tetromino matrix</param> /// <param name="rotateDir">CC / AC rotation </param> /// <param name="T">Referene to current tetromino</param> /// <returns></returns> public int[,] Rotate(int[,] piece, int rotateDir, Tetromino T) { int pieceID = T.GetTetrominoID(); int rotID = T.RotateID; //Set proper rotation and clamp within list limits rotID += rotateDir; if (rotID < 0) { rotID = 3; } else if (rotID > 3) { rotID = 0; } List <int [, ]> pieceRotations; //Get rotation matrix based on proper id and type if (ALL_pieces.TryGetValue(T.GetTetrominoType(), out pieceRotations)) { int[,] rotatedMatrix = pieceRotations[rotID]; return(rotatedMatrix); } else { DebugUtils.LogError(this, T.GetTetrominoType() + " is not a valid tetromino type"); return(piece); } }
private void RenderNextTetromino(Tetromino tetromino) { tetromino.RenderShape(Controls); Tetromino.ActiveTetromino = tetromino; tetromino.TetrominoDocked += ActiveTetromino_TetrominoDocked; DeclareNextTetromino(); }
public static BlockColors GetBlockColors(int LevelNumber, Tetromino Source) { char sTetChar = 'T'; if (Source is Tetromino_T) { sTetChar = 'T'; } else if (Source is Tetromino_J) { sTetChar = 'J'; } else if (Source is Tetromino_Z) { sTetChar = 'Z'; } else if (Source is Tetromino_O) { sTetChar = 'O'; } else if (Source is Tetromino_S) { sTetChar = 'S'; } else if (Source is Tetromino_L) { sTetChar = 'L'; } else if (Source is Tetromino_I) { sTetChar = 'I'; } return(GetBlockColors(LevelNumber, sTetChar)); }
/// <summary> /// Used to check if tetromino is colliding /// with another tetromino piece or the bottom of the map /// </summary> /// <returns>true on collision</returns> public bool CheckPlaceCollision(Tetromino tetromino) { // Checks collision with another tetromino for (int y = 0; y < tetromino.Height; y++) { for (int x = 0; x < tetromino.Width; x++) { // Skips empty fields if (tetromino[x, y] != Field.Empty) { // Checks for solid field if (CheckSolidField(tetromino.X + x, tetromino.Y + y)) { return(true); } // Checks if tetromino reached the bottom if (tetromino.Y + y >= Height) { return(true); } } } } return(false); }
private void RenderNewRandomTetromino() { Tetrominos tetrominoType = (Tetrominos)Tetromino.Rnd.Next(0, Enum.GetNames(typeof(Tetrominos)).Length); Tetromino t = GetTetromino(tetrominoType); RenderNextTetromino(t); }
public void UpdateGrid(Tetromino tetromino) { //not clear now for (int y = 0; y < gridHeight; ++y) { for (int x = 0; x < gridWidth; ++x) { if (grid[x, y] != null) { if (grid[x, y].parent == tetromino.transform) { grid[x, y] = null; } } } } // set the grid with the minos in transform foreach (Transform mino in tetromino.transform) { Vector2 pos = GetInteger(mino.position); if (pos.y < gridHeight) { grid[(int)pos.x, (int)pos.y] = mino; } } }
public bool IsTetrominoValidPosition(Tetromino tetromino) { foreach (Transform minoTransform in tetromino.transform) { if (!minoTransform.CompareTag("Mino")) { continue; } var position = minoTransform.position; var roundedX = Mathf.FloorToInt(position.x); var roundedY = Mathf.FloorToInt(position.y); if (!IsInsideGrid(roundedX, roundedY)) { return(false); } if (_grid[roundedX, roundedY] != null) { return(false); } } return(true); }
public void UpdateGrid(Tetromino tetromino)// обновления границ поля { for (int y = 0; y < gridHeight; y++) { for (int x = 0; x < gridWidth; x++) { if (grid[x, y] != null) { if (grid[x, y].parent == tetromino.transform) { grid[x, y] = null; } } } } foreach (Transform mino in tetromino.transform) { Vector2 pos = Round(mino.position); if (pos.x > checkingFieldOverflow) { pos.x = pos.x - fieldChangeToNormalValue; } if (pos.y < gridHeight) { grid[(int)pos.x, (int)pos.y] = mino; } } }
public void SpawnNextTetromino() // спавнит фигуры { if (!gameStarted) // если игра только началась, создает фигуру для управления и показывает следующую фигуру { grid = new Transform[gridWidth, gridHeight]; currentScore = 0; numLineCleared = 0; gameStarted = true; previewTetromino = Instantiate(GetRandomTetromino(), previewPoint, Quaternion.identity, locationspawn); nextTetromino = Instantiate(GetRandomTetromino(), spawnPoint, Quaternion.identity, locationspawn); previewTetromino.GetComponent <Tetromino>().enabled = false; previewTetromino.GetComponent <GhostTetromino>().enabled = false; nextTetromino.GetComponent <GhostTetromino>().enabled = false; GlobalScore.Instance.Global(this, nextTetromino); nextTetromino.Initialize(this); SpawnGhostTetromino(); } else//если игра уже идет, следующую фигуру перемещает под управление игрока и показывает следующую фигуру { previewTetromino.transform.position = spawnPoint; nextTetromino = previewTetromino; nextTetromino.GetComponent <Tetromino>().enabled = true; previewTetromino = Instantiate(GetRandomTetromino(), previewPoint, Quaternion.identity, locationspawn); previewTetromino.GetComponent <Tetromino>().enabled = false; previewTetromino.GetComponent <GhostTetromino>().enabled = false; nextTetromino.GetComponent <GhostTetromino>().enabled = false; GlobalScore.Instance.Global(this, nextTetromino); nextTetromino.Initialize(this); SpawnGhostTetromino(); } }
public static Tetromino createTetromino(GameField field) { Tetromino newTetromino = TetrominoControls.ttm_create_new(field); TetrominoControls.bn_map_forEachTrue(GraphicDefs.blk_draw, newTetromino); return(newTetromino); }
} // Deletes the row public void UpdateGrid(Tetromino tetromino) // Updates grid dimensions whenever the method is called { for (int y = 0; y < gridHeight; ++y) { for (int x = 0; x < gridWidth; ++x) { if (grid[x, y] != null) { if (grid[x, y].parent == tetromino.transform) { grid[x, y] = null; } } } } foreach (Transform mino in tetromino.transform) { Vector2 pos = Round(mino.position); if (pos.y < gridHeight) { grid[(int)pos.x, (int)pos.y] = mino; } } }
void Awake() { NeedyModule = GetComponent <KMNeedyModule> (); NeedyModule.OnNeedyActivation += OnNeedyActivation; NeedyModule.OnNeedyDeactivation += OnNeedyDeactivation; NeedyModule.OnTimerExpired += OnTimerExpired; /*MoveLeftButton.OnInteract += delegate() { return MoveLeft (); }; * MoveRightButton.OnInteract += delegate() { return MoveRight (); }; * TurnLeftButton.OnInteract += delegate() { return TurnLeft (); }; * TurnRightButton.OnInteract += delegate() { return TurnRight (); }; * DownButton.OnInteract += delegate() { return Down (); };*/ ObjectGrid = new GameObject[G_WIDTH, G_WIDTH]; GameBoard = new TetrisBoard(G_WIDTH, G_WIDTH); // Populate the grid for (int x = 0; x < G_WIDTH; x++) { GameObject col = Board.transform.Find("Col" + x).gameObject; for (int y = 0; y < G_WIDTH; y++) { GameObject go = col.transform.Find("Quad" + y).gameObject; go.SetActive(false); ObjectGrid [x, G_WIDTH - y - 1] = go; } } tetr = null; piecesLeft = 0; UpdateGrid(); }
public void TetrominoFall(Tetromino tetromino) { if (!IsAboveTopLine(tetromino)) { EndGame?.Invoke(); } AddTetrominoToGrid(tetromino); var completedLineIndexes = FindCompletedLines(); var deletedLineCount = 0; foreach (var lineIndex in completedLineIndexes) { DeleteCompletedLine(lineIndex); MoveUpperLinesDown(lineIndex); deletedLineCount++; } if (deletedLineCount > 0) { LinesDestroyed?.Invoke(deletedLineCount); } }
public void SetTetromino(Tetromino tetromino) { for (int index = 0; index < tetromino.Blocs.Length; index++) { Bloc tetrominoBloc = tetromino.Blocs[index]; this.SetBloc(tetrominoBloc.Position, tetrominoBloc); } }
public void ClearTetromino(Tetromino tetromino) { for (int index = 0; index < tetromino.Blocs.Length; index++) { Bloc tetrominoBloc = tetromino.Blocs[index]; Bloc currentBloc = this.GetBloc(tetrominoBloc.LastRegisteredPosition); if (currentBloc == null || currentBloc.Tetromino != tetromino) { continue; } this.SetBloc(tetrominoBloc.LastRegisteredPosition, null); } }
protected IEnumerator Loop() { bool lost = false; Debug.Log ("Loop started"); // TODO: Play start sound // TODO: Start music yield return new WaitForSeconds (1f); while (true) { tetromino = SpawnNewTetromino (); if (tetromino == null) { lost = true; break; } while (!tetromino.hasLanded) { yield return new WaitForSeconds (1f); tetromino.MoveDown (); } tetromino = null; // TODO: Play block stop sound playArea.FindFullLines (); // TODO: if (Options.tetriFast == false) yield return new WaitForSeconds (1f); } // TODO: Stop music if (lost) { // TODO: Play the "You Lost" sound/song Debug.Log ("You lost!"); } else { // TODO: Play the "You Win!" sound/song Debug.Log ("You win!"); } }
private void Game_CurrentTetrominoChange(object sender, System.EventArgs e) { this.preview.Clear(); Queue<Tetromino.TetrominoType> nextTetrominos = Application.Instance.Game.NextTetrominos; if (nextTetrominos == null) { return; } Tetromino tetromino = new Tetromino(nextTetrominos.Peek(), false); switch (tetromino.Type) { case Tetromino.TetrominoType.I: tetromino.Position = new Position(1, 1); break; case Tetromino.TetrominoType.O: tetromino.Position = new Position(2, 1); break; case Tetromino.TetrominoType.T: tetromino.Position = new Position(1, 2); break; case Tetromino.TetrominoType.L: tetromino.Position = new Position(1, 2); break; case Tetromino.TetrominoType.J: tetromino.Position = new Position(1, 2); break; case Tetromino.TetrominoType.Z: tetromino.Position = new Position(1, 2); break; case Tetromino.TetrominoType.S: tetromino.Position = new Position(1, 2); break; } this.preview.SetTetromino(tetromino); }
public Tetromino CreateGhost() { Tetromino clone = new Tetromino(this.Type, true); clone.Position = this.Position; clone.Angle = this.Angle; return clone; }