public void ResetGame() { gameOverPanel.SetActive(false); pauseButton.interactable = true; _totalScores = 0; _gameSpeedCoef = 1; _linesRemoved = 0; gameSpeedText.text = _gameSpeedCoef.ToString("F2"); scoresText.text = _totalScores.ToString(); linesRemovedText.text = _linesRemoved.ToString(); CleanField(); _spawner.DestroySpawnedShapes(); _currentShape = null; _currentTime = 0; _currentMovementDeltaTime = baseMovementDeltaTime; _gameSpeedLevel = 0; _currentTime = 0; _firstStep = true; Time.timeScale = 1; _currentShape = _spawner.SpawnNext(); _gameFinished = false; }
void SpawnShape() { _currentShape = _spawner.SpawnNext(); _firstStep = true; if (PosIsValid(_currentShape.transform)) { UpdateGameField(_currentShape.transform); } else { Destroy(_currentShape.gameObject); FinishGame(); } }
public ShapeProps SpawnNext() { _spawnedObj.transform.SetParent(transform); _spawnedObj.transform.position = transform.position; var lowestPoint = _spawnedSp.LowestPoint(); int deltaY = Tetris.PositionY(transform) - (int)Mathf.Round(lowestPoint.y); if (deltaY > 0) { _spawnedObj.transform.position = new Vector3(transform.position.x, transform.position.y + deltaY, 0); } ShapeProps sp = _spawnedSp; NextShape(); return(sp); }
// Update is called once per frame void Update() { if (_gameFinished || _onPause) { return; } if (Time.time - _currentTime >= _currentMovementDeltaTime) { _currentShape.transform.position += new Vector3(0, -1, 0); if (PosIsValid(_currentShape.transform)) { UpdateGameField(_currentShape.transform); _firstStep = false; } else { if (_firstStep) { FinishGame(); return; } _currentShape.transform.position += new Vector3(0, 1, 0); _currentShape = null; if (CheckFilledLines()) { scoresText.text = _totalScores.ToString(); linesRemovedText.text = _linesRemoved.ToString(); } SpawnShape(); } _currentTime = Time.time; return; } CheckUserInput(); }
void NextShape() { int next = 0; for (int i = 0; i < 4; i++) { next = Random.Range(0, 10000) % shapeList.Length; if (!_usedElements.Contains(next)) { break; } } _spawnedObj = Instantiate(shapeList[next], nextShapePoint.transform); _spawnedSp = _spawnedObj.GetComponent <ShapeProps>(); for (int i = 0; i < (int)Random.Range(0, 4); i++) { _spawnedSp.RotateRight(); } SaveToUsedElements(next); }