public void UpdatePosition(Vector2 upperLeft, Vector2 tileSizes) { for (var c = 0; c < NumColumns; c++) { for (var r = 0; r < NumRows; r++) { var pos = PlayfieldManager.ComputePos(upperLeft, tileSizes, c, r); _tiles[c, r].Position = pos; } } }
public void AnimateTo(Vector2 upperLeft, Vector2 tileSizes, TileAnimParams animParams) { for (var c = 0; c < NumColumns; c++) { for (var r = 0; r < NumRows; r++) { var prevPos = _tiles[c, r].Position; var newPos = PlayfieldManager.ComputePos(upperLeft, tileSizes, c, r); _tiles[c, r].AnimateTo(prevPos, newPos, animParams); } } }
bool isValidGridPos() { foreach (Transform child in currentFigureTransform) { Vector2 v = PlayfieldManager.roundVec2(child.position); // Not inside Border? if (!PlayfieldManager.insideBorder(v)) { return(false); } // Block isn't on an empty spot if (PlayfieldManager.grid[(int)v.x, (int)v.y] != null && PlayfieldManager.grid[(int)v.x, (int)v.y].parent != currentFigureTransform) { Debug.Log("Check if it was just spawned"); // Check if it was just spawned if ((int)v.y >= 17) { Debug.Log("GAME OVER"); Destroy(currentFigureTransform.gameObject); int b; if (scorenumber == 0) { b = -1; } else { b = CheckScoreBoard.isScoreToBeInBoard(scorenumber); } if (b != -1) { SceneManager.LoadScene(loadPlayerName); } else { Application.Quit(); EditorApplication.isPlaying = false; } } return(false); } } return(true); }
// Use this for initialization void Start() { var go = GameObject.Find("Playfield"); PlayfieldManager = go.GetComponent <PlayfieldManager>(); #if TEXTPRO_CRAP _arrowTranslate = arrowText.GetComponent <RectTransform>().position; arrowText.SetActive(false); _bonusTranslate = bonusText.GetComponent <RectTransform>().position; bonusText.SetActive(false); _initialTextSize = scoreValue.GetComponent <TextMeshPro>().fontSize; #endif PlayfieldManager.Playfield.Stats.OnBonusMultiplier += Stats_OnBonusMultiplier; PlayfieldManager.Playfield.Stats.OnColorBonus += Stats_OnColorBonus; PlayfieldManager.Playfield.Stats.OnEmptyBonus += Stats_OnEmptyBonus; }
void updateGrid() { for (int y = 0; y < 20; ++y) { for (int x = 0; x < 10; ++x) { if (PlayfieldManager.grid[x, y] != null) { if (PlayfieldManager.grid[x, y].parent == currentFigureTransform) { PlayfieldManager.grid[x, y] = null; } } } } foreach (Transform child in currentFigureTransform) { Vector2 v = PlayfieldManager.roundVec2(child.position); PlayfieldManager.grid[(int)v.x, (int)v.y] = child; } }
void Update() { // Move Left if (Input.GetKeyDown(KeyCode.LeftArrow)) { if (currentFigureTransform == null) { updateCurrentTransform(); } currentFigureTransform.position += new Vector3(-1, 0, 0); if (isValidGridPos()) { updateGrid(); } else { currentFigureTransform.position += new Vector3(1, 0, 0); } } // Move Right else if (Input.GetKeyDown(KeyCode.RightArrow)) { if (currentFigureTransform == null) { updateCurrentTransform(); } currentFigureTransform.position += new Vector3(1, 0, 0); if (isValidGridPos()) { updateGrid(); } else { currentFigureTransform.position += new Vector3(-1, 0, 0); } } // Rotate else if (Input.GetKeyDown(KeyCode.UpArrow)) { if (currentFigureTransform == null) { updateCurrentTransform(); } currentFigureTransform.Rotate(0, 0, -90); if (isValidGridPos()) { updateGrid(); } else { currentFigureTransform.Rotate(0, 0, 90); Debug.Log(currentFigureTransform.position); } } // Move Downwards and Fall else if (Input.GetKeyDown(KeyCode.DownArrow) || (Time.time - lastFall >= 1)) { if (Input.GetKeyDown(KeyCode.DownArrow)) { fallingIndex++; } for (int i = 0; i < fallingIndex; ++i) { if (currentFigureTransform == null) { updateCurrentTransform(); } currentFigureTransform.position += new Vector3(0, -1, 0); if (isValidGridPos()) { updateGrid(); } else { currentFigureTransform.position += new Vector3(0, 1, 0); Sound.playLanding(); score = PlayfieldManager.deleteFullRows(); if (score > 0) { scorenumber = Scoring.SetScore(score, textScore); } FreeChildren(); FindObjectOfType <Spawner>().SpawnElement(); updateCurrentTransform(); break; } } fallingIndex = 1; lastFall = Time.time; } }
void Awake() { Instance = this; }