public tetris_Shape SpawnShape() { tetris_Shape shape = null; //shape = Instantiate(GetRandomShape(), transform.position, Quaternion.identity) as tetris_Shape; shape = GetQueuedShape(); shape.transform.position = transform.position; //shape.transform.localScale = Vector3.one; StartCoroutine(GrowShape(shape, transform.position, 0.30f)); if (m_spawnFx) { m_spawnFx.Play(); } if (shape) { return(shape); } else { Debug.LogWarning("WARNING! Invalid shape in spawner!"); return(null); } }
public void DrawGhost(tetris_Shape originalShape, tetris_Board gameBoard) { if (!m_ghostShape) { m_ghostShape = Instantiate(originalShape, originalShape.transform.position, originalShape.transform.rotation) as tetris_Shape; m_ghostShape.gameObject.name = "GhostShape"; SpriteRenderer[] allRenders = m_ghostShape.GetComponentsInChildren <SpriteRenderer>(); foreach (SpriteRenderer r in allRenders) { r.color = m_color; } } else { m_ghostShape.transform.position = originalShape.transform.position; m_ghostShape.transform.rotation = originalShape.transform.rotation; m_ghostShape.transform.localScale = Vector3.one; } m_hitBottom = false; while (!m_hitBottom) { m_ghostShape.MoveDown(); if (!gameBoard.IsValidPosition(m_ghostShape)) { m_ghostShape.MoveUp(); m_hitBottom = true; } } }
// Use this for initialization void Start() { //if (diagnosticText){diagnosticText.text = "";} //m_gameBoard = GameObject.FindWithTag("Board").GetComponent<tetris_Board>(); // m_gameBoard = GameObject.FindObjectsOfType<tetris_Board>(); m_timeToNextKeyLeftRight = Time.time + m_keyRepeatRateLeftRight; m_timeToNextKeyDown = Time.time + m_keyRepeatRateDown; m_timeToNextKeyRotate = Time.time + m_keyRepeatRateRotate; m_gameBoard = GameObject.FindObjectOfType(typeof(tetris_Board)) as tetris_Board; m_spawner = GameObject.FindWithTag("Spawner").GetComponent <tetris_Spawner>(); m_soundManager = GameObject.FindObjectOfType <tetris_SoundManager>(); m_scoreManager = GameObject.FindObjectOfType <tetris_ScoreManager>(); m_ghost = GameObject.FindObjectOfType <tetris_Ghost>(); m_holder = GameObject.FindObjectOfType <tetris_Holder>(); if (!m_scoreManager) { Debug.LogWarning("WARNING! There is no scoreManager defined!"); } if (!m_soundManager) { Debug.LogWarning("WARNING! There is no soundManager defined!"); } if (!m_gameBoard) { Debug.Log("WARNING! There is no game board defined"); } if (!m_spawner) { Debug.Log("WARNING! There is no game spawner defined"); } else { m_spawner.transform.position = tetris_Vectorf.Round(m_spawner.transform.position); if (!m_activeShape) { m_activeShape = m_spawner.SpawnShape(); } } if (m_gameOverPanel) { m_gameOverPanel.SetActive(false); } if (m_gamePausePanel) { m_gamePausePanel.SetActive(false); } m_dropIntervalModded = m_dropInterval; }
public void Hold() { if (!m_holder) { return; } if (!m_holder.m_heldShape) { m_holder.Catch(m_activeShape); m_activeShape = m_spawner.SpawnShape(); PlaySound(m_soundManager.m_holdSound); } else if (m_holder.m_canRelease) { tetris_Shape shape = m_activeShape; m_activeShape = m_holder.Release(); m_activeShape.transform.position = m_spawner.transform.position; m_holder.Catch(shape); PlaySound(m_soundManager.m_holdSound); } else { Debug.LogWarning("HOLDER WARNING! Wait for cool down!"); PlaySound(m_soundManager.m_errorSound); } if (m_ghost) { m_ghost.Reset(); } }
public void Catch(tetris_Shape shape) { if (m_heldShape) { Debug.LogWarning("HOLDER WARNING: Release a shape before trying to hold!"); return; } if (!shape) { Debug.LogWarning("HOLDER WARNING! Invalid shape!"); return; } if (m_holderXform) { shape.transform.position = m_holderXform.position + shape.m_queueOffset; shape.transform.localScale = Vector3.one * m_scale; m_heldShape = shape; shape.transform.rotation = Quaternion.identity; } else { Debug.LogWarning("HOLDER WARNING! Holder has no transform assigned"); } }
public bool IsOverLimit(tetris_Shape shape) { foreach (Transform child in shape.transform) { if (child.transform.position.y >= (m_height - m_header - 1)) { return(true); } } return(false); }
public tetris_Shape Release() { m_heldShape.transform.localScale = Vector3.one; tetris_Shape shape = m_heldShape; m_heldShape = null; m_canRelease = false; return(shape); }
private void LandShape() { // shape lands here if (m_activeShape) { m_timeToNextKeyLeftRight = Time.time; m_timeToNextKeyDown = Time.time; m_timeToNextKeyRotate = Time.time; m_activeShape.MoveUp(); m_gameBoard.StoreShapeInGrid(m_activeShape); m_activeShape.LandShapeFX(); if (m_ghost) { m_ghost.Reset(); } if (m_holder) { m_holder.m_canRelease = true; } m_activeShape = m_spawner.SpawnShape(); m_gameBoard.StartCoroutine("ClearAllRows"); PlaySound(m_soundManager.m_dropSound, 0.5f); if (m_gameBoard.m_completedRows > 0) { m_scoreManager.ScoreLines(m_gameBoard.m_completedRows); if (m_scoreManager.m_didLevelUp) { PlaySound(m_soundManager.m_levelUpVocalClip, 1f); m_dropIntervalModded = Mathf.Clamp(m_dropInterval - (((float)m_scoreManager.m_level - 1) * 0.03f), 0.05f, 1f); } else { if (m_gameBoard.m_completedRows > 1) { AudioClip randomVocal = m_soundManager.GetRandomClip(m_soundManager.m_vocalClips); PlaySound(randomVocal, 0.5f); } } PlaySound(m_soundManager.m_clearRowSound, 0.7f); } } }
public void StoreShapeInGrid(tetris_Shape shape) { if (shape == null) { return; } foreach (Transform child in shape.transform) { Vector2 pos = tetris_Vectorf.Round(child.position); m_grid[(int)pos.x, (int)pos.y] = child; } }
public bool IsValidPosition(tetris_Shape shape) { foreach (Transform child in shape.transform) { Vector2 pos = tetris_Vectorf.Round(child.position); if (!IsWithinBoard((int)pos.x, (int)pos.y)) { return(false); } if (IsOccupied((int)pos.x, (int)pos.y, shape)) { return(false); } } return(true); }
IEnumerator GrowShape(tetris_Shape shape, Vector3 position, float growTime = 0.5f) { float size = 0f; growTime = Mathf.Clamp(growTime, 0.1f, 2f); // 1 units/seconds * seconds/frame = units / frame float sizeDelta = Time.deltaTime / growTime; while (size < 1f) { shape.transform.localScale = Vector3.one * size; size += sizeDelta; shape.transform.position = position; yield return(null); //wait until the next frame } shape.transform.localScale = Vector3.one; }
tetris_Shape GetQueuedShape() { tetris_Shape firstShape = null; if (m_queuedShapes[0]) { firstShape = m_queuedShapes[0]; } for (int i = 1; i < m_queuedShapes.Length; i++) { m_queuedShapes[i - 1] = m_queuedShapes[i]; m_queuedShapes[i - 1].transform.position = m_queueXforms[i - 1].position + m_queuedShapes[i].m_queueOffset; } m_queuedShapes[m_queuedShapes.Length - 1] = null; FillQueue(); return(firstShape); }
bool IsOccupied(int x, int y, tetris_Shape shape) { return((m_grid[x, y] != null) && m_grid[x, y].parent != shape.transform); }