protected bool CanPlace(Grid grid, Tetronimo t, int x, int y) { switch (t.TetronimoType) { case TetronimoType.L: return(new L_PiecePlacer().CanPlace(grid, t, x, y)); break; case TetronimoType.S: return(new S_PiecePlacer().CanPlace(grid, t, x, y)); break; case TetronimoType.T: return(new T_PiecePlacer().CanPlace(grid, t, x, y)); break; case TetronimoType.I: return(new I_PiecePlacer().CanPlace(grid, t, x, y)); break; default: throw new ArgumentOutOfRangeException(); } }
public bool Place(Grid grid, Tetronimo current, Tetronimo next) { if (current.TetronimoType == TetronimoType.I) { current.Rotation = Rotation.Ninety; for (int i = 0; i < grid.Columns; i++) { if (CanPlace(grid, current, i, 0)) { CommitPlacement(grid, current, i, 0); return(true); } else if (CanPlace(grid, current, i, grid.Rows - 1)) { CommitPlacement(grid, current, i, grid.Rows - 1); return(true); } } current.Rotation = Rotation.Zero; for (int i = 0; i < grid.Rows; i++) { if (CanPlace(grid, current, 0, i)) { CommitPlacement(grid, current, i, 0); return(true); } else if (CanPlace(grid, current, grid.Columns - 1, i)) { CommitPlacement(grid, current, grid.Columns - 1, i); return(true); } } } return(_placer.Place(grid, current, next)); }
public void Place(Grid g, Tetronimo t, int x, int y) { if (t.Rotation == Rotation.Zero) { g.Mark(x, y, t.TetronimoType); g.Mark(x + 1, y, t.TetronimoType); g.Mark(x + 2, y, t.TetronimoType); g.Mark(x + 1, y + 1, t.TetronimoType); } if (t.Rotation == Rotation.Ninety) { g.Mark(x, y, t.TetronimoType); g.Mark(x + 1, y, t.TetronimoType); g.Mark(x + 1, y + 1, t.TetronimoType); g.Mark(x + 1, y - 1, t.TetronimoType); } if (t.Rotation == Rotation.OneEighty) { g.Mark(x, y, t.TetronimoType); g.Mark(x + 1, y, t.TetronimoType); g.Mark(x + 2, y, t.TetronimoType); g.Mark(x + 1, y + 1, t.TetronimoType); } if (t.Rotation == Rotation.TwoSeventy) { g.Mark(x, y, t.TetronimoType); g.Mark(x, y + 1, t.TetronimoType); g.Mark(x, y + 2, t.TetronimoType); g.Mark(x + 1, y + 1, t.TetronimoType); } }
public void AddPiece(Tetronimo piece) { if (pieces.Count >= TetrisController.Rules.maxPiecesInQueue) { return; } GameObject go = Instantiate <GameObject>(piece.group, this.transform); go.transform.Rotate(0, 0, piece.queueRotation); QueuedPiece t = new QueuedPiece(); t.transform = go.transform; t.tetronimo = piece; pieces.Add(t); selector.gameObject.SetActive(true); LayoutPieces(); // Play effect AFTER layout so they are in the correct spot Group group = go.GetComponent <Group>(); if (group) { group.PlaySettleEffects(addEffect, true); } }
public void Place(Grid g, Tetronimo t, int x, int y) { if (t.Rotation == Rotation.Zero) { for (int i = 0; i < 3; i++) { g.Mark(x, y + i, t.TetronimoType); } g.Mark(x + 1, y + 2, t.TetronimoType); } else if (t.Rotation == Rotation.Ninety) { for (int i = 0; i < 3; i++) { g.Mark(x + i, y, t.TetronimoType); } g.Mark(x, y + 1, t.TetronimoType); } else if (t.Rotation == Rotation.OneEighty) { for (int i = 0; i < 3; i++) { g.Mark(x + 1, y + i, t.TetronimoType); } g.Mark(x, y, t.TetronimoType); } else if (t.Rotation == Rotation.TwoSeventy) { for (int i = 0; i < 3; i++) { g.Mark(x + i, y, t.TetronimoType); } g.Mark(x + 2, y + 1, t.TetronimoType); } }
public override void _Draw() { if (!debug) { return; } Tetronimo t = gameInstance.currentTetronimo; }
public void AddPiece(Tetronimo piece) { Group group = spawner.SpawnTetronimo(piece); group.lastFallTime = Time.time; group.gridModel = gridModel; activeGroups.Add(group); }
private Tetronimo SpawnTetronimo() { Tetronimo t = GenerateTetronimo(); AddChild(t); currentTetronimo = t; t.Move(2, 2); gameBorder.Raise(); return(t); }
public bool SpawnSelected() { Tetronimo piece = queue.GetSelectedPiece(); if (piece) { AddPiece(piece); queue.RemoveSelectedPiece(); return(true); } return(false); }
private void OnGameOver() { if (gameOver) { return; } currentTetronimo.QueueFree(); currentTetronimo = null; gameOver = true; CalculateScore(); EmitSignal("GameOver"); Modulate *= new Color(.5f, .5f, .5f); }
public Input Import(string path) { var input = new Input(); input.TetronimoSequence = new List <Tetronimo>(); foreach (string line in File.ReadAllLines(path)) { var t = new Tetronimo(); t.TetronimoType = (TetronimoType)Enum.Parse(typeof(TetronimoType), line); input.TetronimoSequence.Add(t); } return(input); }
public Group SpawnTetronimo(Tetronimo piece) { GameObject go = Instantiate(piece.group, transform.position, Quaternion.Euler(0, 0, piece.spawnRotation) ) as GameObject; if (go != null) { Group group = go.GetComponent <Group>(); return(group); } return(null); }
// Update is called once per frame void Update() { if (!TetrisController.Rules.ready) { return; } if (TetrisController.Rules.matchesMade.Count > 0) { Debug.Log("Found matches: " + TetrisController.Rules.matchesMade.Count); for (int i = 0; i < TetrisController.Rules.matchesMade.Count; ++i) { int index = TetrisController.Rules.matchesMade[i]; if (index > TetrisController.Rules.tetronimos.Length || index == -1) { index = Random.Range(0, TetrisController.Rules.tetronimos.Length); } Tetronimo tetronimo = TetrisController.Rules.tetronimos[index]; AddPiece(tetronimo); } TetrisController.Rules.matchesMade.Clear(); } LayoutPieces(); if (selector) { if (Input.GetKeyDown(KeyCode.DownArrow) && selectorIndex < (pieces.Count - 1)) { MoveSelectorDown(); } if (Input.GetKeyDown(KeyCode.UpArrow) && selectorIndex > 0) { MoveSelectorUp(); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { dropNow = true; } if (Input.GetKeyDown(KeyCode.RightArrow)) { RemoveSelectedPiece(); } } }
public void Place(Grid g, Tetronimo t, int x, int y) { if (t.Rotation == Rotation.Zero || t.Rotation == Rotation.OneEighty) { for (int i = 0; i < 4; i++) { g.Mark(x, y + i, t.TetronimoType); } } else { for (int i = 0; i < 4; i++) { g.Mark(x + i, y, t.TetronimoType); } } }
public bool Place(Grid grid, Tetronimo current, Tetronimo next) { var maxTries = 1000; for (int i = 0; i < maxTries; i++) { var x = _random.Next(grid.Columns); var y = _random.Next(grid.Rows); current.Rotation = (Rotation)_random.Next(4); if (CanPlace(grid, current, x, y)) { CommitPlacement(grid, current, x, y); return(true); } } return(false); }
public void UpdateSensors() { for (int x = 0; x < gameInstance.width; x++) { sensorGameState[x] = 2f; } sensorPosX = 2f; sensorPosY = 2f; sensorTetrominoTypeRotation = 2f; Tetronimo t = gameInstance.currentTetronimo; if (t == null) { return; } for (int x = 0; x < gameInstance.width; x++) { float columnState = 0; float maxState = 0; for (int y = 0; y < gameInstance.height; y++) { if (gameInstance.grid[y, x] != 0) { columnState += Mathf.Pow(2, y); } maxState += Mathf.Pow(2, y); } float d = columnState / maxState; sensorGameState[x] = d * 2f; } sensorPosX = t.posX / (float)gameInstance.width; sensorPosY = t.posY / (float)gameInstance.height; float rotationType = (int)t.type * 4f + t.rotation; sensorTetrominoTypeRotation = rotationType / (7f * 4f); /*sensorTetrominoType = (int)t.type / 7f; * sensorTetrominoRotation = t.rotation / 4f;*/ if (debug) { Update(); } }
public bool CanPlace(Grid g, Tetronimo t, int x, int y) { if (t.Rotation == Rotation.Zero) { bool isAvailable = true; isAvailable &= g.IsAvailable(x, y); isAvailable &= g.IsAvailable(x + 1, y); isAvailable &= g.IsAvailable(x + 1, y + 1); isAvailable &= g.IsAvailable(x + 2, y + 1); return(isAvailable); } if (t.Rotation == Rotation.Ninety) { bool isAvailable = true; isAvailable &= g.IsAvailable(x, y); isAvailable &= g.IsAvailable(x, y + 1); isAvailable &= g.IsAvailable(x + 1, y + 1); isAvailable &= g.IsAvailable(x + 1, y + 2); return(isAvailable); } if (t.Rotation == Rotation.OneEighty) { bool isAvailable = true; isAvailable &= g.IsAvailable(x, y); isAvailable &= g.IsAvailable(x + 1, y); isAvailable &= g.IsAvailable(x + 1, y + 1); isAvailable &= g.IsAvailable(x + 2, y + 1); return(isAvailable); } if (t.Rotation == Rotation.TwoSeventy) { bool isAvailable = true; isAvailable &= g.IsAvailable(x, y); isAvailable &= g.IsAvailable(x, y + 1); isAvailable &= g.IsAvailable(x + 1, y + 1); isAvailable &= g.IsAvailable(x + 1, y + 2); return(isAvailable); } return(false); }
// Start is called before the first frame update void Start() { LastFall = 0; CurrentLines = 0; CurrentFallInterval = FallInterval; Playfield.deleteAll(); Playfield.insertLines(InitialLines, Brick); //Chooses 4 initial random pieces Tetronimo InitialPiece0 = ChooseRandomPiece(); Tetronimo InitialPiece1 = ChooseRandomPiece(); Tetronimo InitialPiece2 = ChooseRandomPiece(); Tetronimo InitialPiece3 = ChooseRandomPiece(); //Adds to the list of Next Pieces to spawn NextPieces = new List <Tetronimo>(); NextPieces.Add(InitialPiece0); NextPieces.Add(InitialPiece1); NextPieces.Add(InitialPiece2); NextPieces.Add(InitialPiece3); //Updates de display of each UI NextPiecesUI[0].ChangeDisplayPiece(InitialPiece0.PieceNumber); NextPiecesUI[0].ChangeDisplayPiece(InitialPiece0.PieceNumber); NextPiecesUI[0].ChangeDisplayPiece(InitialPiece0.PieceNumber); NextPiecesUI[0].ChangeDisplayPiece(InitialPiece0.PieceNumber); //Spawns the first Piece SpawnNext(); Progress.SetObjective(ObjectiveLines); BGMusic.Instance.ResetPitch(); if (CurrentLevel == Level.Level1) { Timer.Instance.StartTimer(); } else { Timer.Instance.Resume(); } }
public bool CanPlace(Grid g, Tetronimo t, int x, int y) { bool isAvailable = true; if (t.Rotation == Rotation.Zero || t.Rotation == Rotation.OneEighty) { for (int i = 0; i < 4; i++) { isAvailable &= g.IsAvailable(x, y + i); } } else { for (int i = 0; i < 4; i++) { isAvailable &= g.IsAvailable(x + i, y); } } return(isAvailable); }
public bool CanPlace(Grid g, Tetronimo t, int x, int y) { var isAvailable = true; if (t.Rotation == Rotation.Zero) { for (int i = 0; i < 3; i++) { isAvailable &= g.IsAvailable(x, y + i); } isAvailable &= g.IsAvailable(x + 1, y + 2); } else if (t.Rotation == Rotation.Ninety) { for (int i = 0; i < 3; i++) { isAvailable &= g.IsAvailable(x + i, y); } isAvailable &= g.IsAvailable(x, y + 1); } else if (t.Rotation == Rotation.OneEighty) { for (int i = 0; i < 3; i++) { isAvailable &= g.IsAvailable(x + 1, y + i); } isAvailable &= g.IsAvailable(x, y); } else if (t.Rotation == Rotation.TwoSeventy) { for (int i = 0; i < 3; i++) { isAvailable &= g.IsAvailable(x + i, y); } isAvailable &= g.IsAvailable(x + 2, y + 1); } return(isAvailable); }
protected void CommitPlacement(Grid grid, Tetronimo t, int x, int y) { switch (t.TetronimoType) { case TetronimoType.L: new L_PiecePlacer().Place(grid, t, x, y); break; case TetronimoType.S: new S_PiecePlacer().Place(grid, t, x, y); break; case TetronimoType.T: new T_PiecePlacer().Place(grid, t, x, y); break; case TetronimoType.I: new I_PiecePlacer().Place(grid, t, x, y); break; default: throw new ArgumentOutOfRangeException(); } }
private void ControlCurrent(float delta) { currentFallDelay -= delta; timeHoldingPiece += delta; if (inputer.rotate) { currentTetronimo.Rotate(); } if (inputer.fall) { currentFallDelay = 0f; } if (inputer.moveLeft) { currentTetronimo.Move(-1, 0); tetrominoDraw = true; } if (inputer.moveRight) { currentTetronimo.Move(1, 0); tetrominoDraw = true; } if (currentFallDelay <= 0f) { currentFallDelay = fallDelay; bool move = currentTetronimo.Move(0, 1); tetrominoDraw = true; if (!move) { MergeCurrentTetronimo(); ScanLines(); timeHoldingPiece = 0f; currentTetronimo.QueueFree(); currentTetronimo = null; SpawnTetronimo(); if (!currentTetronimo.Move(0, 0)) { OnGameOver(); } draw = true; tetrominoDraw = true; } } timeHoldingPiece += delta; if (timeHoldingPiece >= 10f) { currentTetronimo.QueueFree(); currentTetronimo = null; SpawnTetronimo(); tetrominoDraw = true; timeHoldingPiece = 0f; /*currentTetronimo.QueueFree(); * currentTetronimo = null; * gameOver = true; * EmitSignal("GameOver"); * Modulate *= new Color(.5f, .5f, .5f);*/ } }