/// <summary> /// Generates a tetromino by its name. Mostly for testing purposes. But if i continued, I could add logic to make it as painful for the /// player as possible! /// </summary> /// <param name="c">The name of the tetromino to generate</param> /// <returns>A new tetromino instance</returns> public Tetromino GenerateTetromino(char c) { int value = Array.IndexOf <char>(tetrominoNames, c); TetrominoData mapping = tetrominoMapping[tetrominoNames[value]]; return(new Tetromino(mapping.RotationMatrix, mapping.WallKickData, mapping.CenterTranslation, value)); }
/// <summary> /// Generates a random tetromino and turns it /// </summary> /// <returns>The new Tetromino instance</returns> public Tetromino GenerateRandomTetromino() { int value = bag.GetRandomNumberForTetris(); TetrominoData mapping = tetrominoMapping[tetrominoNames[value]]; return(new Tetromino(mapping.RotationMatrix, mapping.WallKickData, mapping.CenterTranslation, value)); }
private void UpdateHold() { if (board.hold.Count > 0) { holdData = board.tetrominoes[board.hold[0]]; } }
public void Initialized(Board board, Vector3Int position, TetrominoData data) { this.board = board; this.position = position; this.data = data; this.rotationIndex = 0; this.stepTime = Time.time + this.stepDelay; this.lockTime = 0f; this.repeatTime = 0f; this.repeatDir = 0; this.moveCount = 0; this.moveCountMax = 15; this.canHold = true; this.isPause = false; if (this.cells == null) { this.cells = new Vector3Int[data.cells.Length]; } for (int i = 0; i < data.cells.Length; i++) { this.cells[i] = (Vector3Int)data.cells[i]; } }
public void SpawnPiece(string type) { if (type == "normal") { queueIndex = activePiece.Wrap(queueIndex + 1, 0, 7); TetrominoData data = this.tetrominoes[queue[queueIndex]]; if (queueIndex == 6) { NewBag(); } this.activePiece.Initialized(this, this.spawnPosition, data); } else if (type == "swap") { TetrominoData data = this.tetrominoes[hold[0]]; this.activePiece.Initialized(this, this.spawnPosition, data); } if (isValidPosition(this.activePiece, this.spawnPosition)) { Set(this.activePiece); } else { GameOver(); } }