public bool IsBlocking(TetrisBlock block, int x, int y) { for (int ix = 0; ix < block.GetBlockWidth(); ix++) { for (int iy = 0; iy < block.GetBlockHeight(); iy++) { if (direction == Direction.RIGHT) { if (block.blocks[iy,ix] == null) { continue; } } else { if (block.blocks[block.GetBlockHeight()-1-iy,ix] == null) { continue; } } int ny = iy+y; int nx = ix+x; if (ny < 0 || nx < 0 || nx >= blocks.GetLength(1) || ny >= blocks.GetLength(0)) { continue; } if (blocks[iy+y, ix+x] != null) { return true; } } } return false; }
public void add(TetrisBlock currentBlock) { List<int[]> pos = currentBlock.computeActualPos(); for (int i = 0; i < pos.Count; i++) { int[] currentPos = pos[i]; grid[currentPos[0], currentPos[1]].setEmptyness(false); grid[currentPos[0], currentPos[1]].setColor(currentBlock.getColor()); } }
public GameLogic(GameTime value, TetrisGame game) { currentBlock = TetrisBlock.generateBlock(); nextBlock = TetrisBlock.generateBlock(); this.timeOfBeginning = value; beginTime = value.TotalGameTime.Seconds + value.TotalGameTime.Milliseconds/1000.0f; timeSinceBeginning = 0; this.myGame = game; GameLogic.level = 1; GameLogic.score = 0; GameLogic.gameOver = false; }
public bool Fire(TetrisBlock block, int xPosition, bool canWin) { for (int y = FieldDefinition.instance.height-1; y >= 0; y--) { if (IsBlocking(block, xPosition, y)) { if (!PutBlock(block, xPosition, y+1, canWin)) { return false; } return true; } } PutBlock(block, xPosition, 0, canWin); return true; }
public bool canAdd(TetrisBlock blockToAdd) { List<int[]> pos = blockToAdd.computeActualPos(); for (int i = 0; i < pos.Count; i++) { int[] currentPos = pos[i]; if (!grid[currentPos[0], currentPos[1]].isEmpty()) { return false; } } return true; }
public Options(Texture2D blockSprite, Texture2D resetSprite, Texture2D backSprite, int screenWidth, int screenHeight, SpriteFont spriteFont, BlockList blocks) { block = blockSprite; reset = resetSprite; back = backSprite; this.screenWidth = screenWidth; this.screenHeight = screenHeight; this.blocks = blocks; block1 = blocks.Find(1); block2 = blocks.Find(2); block3 = blocks.Find(3); block4 = blocks.Find(4); block5 = blocks.Find(5); block6 = blocks.Find(6); block7 = blocks.Find(7); font = spriteFont; backRect = new Rectangle(screenWidth / 2 - backSprite.Width / 2, screenHeight - backSprite.Height - 100, backSprite.Width, backSprite.Height); }
void SetNextTetromino() { nextTetromino = GetRandomTetromino(); preview = Instantiate(tetrominos[nextTetromino], previewPosition.transform.position, Quaternion.identity, previewPosition.transform); // Ajusta o tamanho preview.transform.localScale = new Vector3(UIScale, UIScale, 0); // Encontra o Script TetrisBlock tetrisBlock = preview.GetComponent <TetrisBlock>(); // Desativa para parar movimentação tetrisBlock.enabled = false; // Ajusta o offset preview.transform.localPosition -= (tetrisBlock.rotationPoint * UIScale) - (tetrisBlock.previewOffset * UIScale); foreach (Transform children in preview.transform) { children.gameObject.layer = 5; } }
// Use this for initialization void Start() { m_rigidBody = GetComponent <Rigidbody2D>(); grid2Block = new TetrisBlock[GRID_SIZE_X, GRID_SIZE_Y]; gridSideLength = refBlockSpriteRenderer.bounds.size.x; toppestPosition = new Vector3(0.0f, Mathf.NegativeInfinity, 0.0f); TetrisBlock[] childBlocks = new TetrisBlock[transform.childCount]; for (int i = 0; i < transform.childCount; i++) { childBlocks[i] = transform.GetChild(i).GetComponent <TetrisBlock>(); assignToGridSystem(childBlocks[i]); } UpdateCenterOfMass(childBlocks); }
public TetrisBlock blockClone() { TetrisBlock newBlock = new TetrisBlock(); newBlock.block_shape = this.block_shape; for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) { newBlock.coord[i, j] = this.coord[i, j]; } } newBlock.coord_table = this.coord_table; newBlock.Current_X = this.Current_X; newBlock.Current_Y = this.Current_Y; return(newBlock); }
public void moveBlock(char control) //Change the block for either move or spin { switch (control) { case 'a': //left tryMove(current_block, current_block.get_CurrentX(), current_block.get_CurrentY() - 1); break; case 'A': tryMove(current_block, current_block.get_CurrentX(), current_block.get_CurrentY() - 1); break; case 'd': //right tryMove(current_block, current_block.get_CurrentX(), current_block.get_CurrentY() + 1); break; case 'D': tryMove(current_block, current_block.get_CurrentX(), current_block.get_CurrentY() + 1); break; case 's': //down+speed controller.myTimer.Interval = 200; break; case 'S': controller.myTimer.Interval = 50; break; case 'W': //spin if (current_block.getBlockShape() != TetrisBlock.Blocks.No_shape && current_block.getBlockShape() != TetrisBlock.Blocks.Square_shape) { TetrisBlock rotate_test = current_block.blockClone(); rotate_test.rotate(); if (tryMove(rotate_test, rotate_test.get_CurrentX(), rotate_test.get_CurrentY())) { ; } //current_block.rotate(); } break; } }
void updateStateByBlock(TetrisBlock tmpBlock, int stateVal) { int tmpY; int tmpX; // Debug.Log ("center Y:" + tmpBlock.Y + " center X:" + tmpBlock.X); for (int i = 0; i < tmpBlock.listY.GetLength(0); i++) { tmpY = tmpBlock.Y + tmpBlock.listY [i]; tmpX = tmpBlock.X + tmpBlock.listX [i]; if (this.InField(tmpY, tmpX)) { stateArray [tmpY, tmpX] = stateVal; blockArray[tmpY, tmpX] = tmpBlock.blocks[i]; blockArray[tmpY, tmpX].transform.position = blockInFieldPosition(tmpY, tmpX); blockArray[tmpY, tmpX].transform.localScale = Vector3.one; tmpBlock.blocks[i] = null; } } }
// Use this for initialization void Start() { for (int i = 0; i < MAX_ROW; i++) { stateArray [i, 0] = 1; stateArray [i, MAX_COL + 1] = 1; } for (int i = 0; i < MAX_COL + 1; i++) { stateArray [MAX_ROW, i] = 1; } resetStateArray(); this.ghostBlock = new TetrisBlock(INIT_ROW, INIT_COL); this.nextBlock = new TetrisBlock(INIT_ROW, INIT_COL); GenNewBlock(); lastTime = Time.time; updateStateByBlock(curBlock, 1); }
bool IsCollision(int targetRow, int targetCol, TetrisBlock tmpBlock) { int tmpRow; int tmpCol; bool result = false; updateStateByBlock(tmpBlock, 0); for (int i = 0; i < 4; i++) { tmpRow = targetRow + tmpBlock.diffRow [i]; tmpCol = targetCol + tmpBlock.diffCol [i]; if (!this.InField(tmpRow, tmpCol) || (stateArray [tmpRow, tmpCol] == 1)) { result = true; } } updateStateByBlock(tmpBlock, 1); return(result); }
// NOTE: This needs to be fixed, not functional right now. Meant to grab and store stored pieces. public void StorePiece(TetrisBlock tetriminoToStore) { GameObject newTetrimino = FindObjectOfType <PieceStorer>().StorePiece(tetriminoToStore); Destroy(tetriminoToStore.gameObject); if (newTetrimino != null) { foreach (GameObject tetrimino in Tetrominoes) { if (newTetrimino.gameObject.tag == tetrimino.gameObject.tag) { Instantiate(tetrimino, transform.position, Quaternion.identity); } } } else { GrabNextPiece(); } }
public GameWorld(int width, int height, ContentManager Content) { screenWidth = width; screenHeight = height; //current = new ChooseBlock(); //next = new ChooseBlock(); gameState = GameState.Playing; block = Content.Load <Texture2D>("block"); font = Content.Load <SpriteFont>("SpelFont"); grid = new TetrisGrid(block); Iblok = new I(block); Oblok = new O(block); Sblok = new S(block); Zblok = new Z(block); Jblok = new J(block); Lblok = new L(block); Tblok = new T(block); chooseBlock = new ChooseBlock(); tetromino = new TetrisBlock(block); }
public bool tryMove(TetrisBlock block, int newX, int newY) //Check if the block is movable, and then move { for (int i = 0; i < 4; i++) { int x = newX + block.get_X(i); int y = newY + block.get_Y(i); //cannot put curBlock on exist blocks if (x < 0 || x >= (int)constant.BOARD_HEIGHT || y < 0 || y >= (int)constant.BOARD_WIDTH) //block out of board { return(false); } if (board[x, y]) { return(false); } } current_block = block; current_block.set_CurrentX(newX); current_block.set_CurrentY(newY); view.changeView(this); return(true); }
void ghostTetromino() { if (instantiated != null) { Destroy(instantiated); } //GameObject clone = FindObjectOfType<spawn>().getCurrentPiece(); instantiated = (GameObject)Instantiate(gameObject); TetrisBlock ghostPiece = instantiated.GetComponent(typeof(TetrisBlock)) as TetrisBlock; ghostPiece.canMove = false; if (ghostPiece.ValidMove()) { ghostPiece.goDown(); ghostPiece.ghostify(); } else { Destroy(instantiated); } }
public void OnPlaceBlock(TetrisBlock block) { block.enabled = false; for (int i = 0; i < block.transform.childCount; ++i) { Transform piece = block.transform.GetChild(i); UIBackgroundManager.Instance.OnPlacePiece(piece); } //현재 블럭 죽이기 Destroy(block.transform.gameObject); //줄 체크 후 삭제 UIBackgroundManager.Instance.DeleteRows(); UITetrisBlockManager.Instance.SpawnRandomBlock(); //blockManager.SpawnRandomBlock(); }
public void Update(GameTime gameTime) { //spawnt nieuw random block als vorige is geplaatst if (useBlock.setBlock) { CheckIfFullRow(); CheckIfGameOver(); for (int i = 0; i < 4; i++) { CheckIfEmptyLines(); } Spawn(); useBlock = type; nextblock = random.Next(0, 7); Spawn(); previewBlock = type; previewBlock.position = new int[2] { 12, 3 }; } useBlock.Update(gameTime); }
//HandleInput methode voor de TetrisGrid. /// <summary> /// Handles the player input. /// </summary> /// <param name="gameTime">An object with information about the time that has passed in the game.</param> /// <param name="spriteBatch">The SpriteBatch used for drawing sprites and text.</param> /// <param name="LeftMove">When this key is pressed the currently active block is (if possable) moved 1 block to the left in the grid.</param> /// <param name="RightMove">When this key is pressed the currently active block is (if possable) moved 1 block to the right in the grid.</param> /// <param name="RotateCW">When this key is pressed the currently active block is (if possable) rotated 90 degrees Clockwise.</param> /// <param name="RotateCCW">When this key is pressed the currently active block is (if possable) rotated 90 degrees CounterClockwise.</param> /// <param name="GoDown">While this key is pressed the currently active block will move down through the grid at an accelerated speed.</param> public void HandleInput(GameTime gameTime, InputHelper inputHelper, Keys LeftMove, Keys RightMove, Keys RotateCW, Keys RotateCCW, Keys SlamDown, Keys GoDown) { //This part makes sure that the player can move the block to the left and right. if (inputHelper.KeyDown(RightMove) && gameTime.TotalGameTime.Ticks % 6 == 0) //Makes sure the movement is not to fast { Block.MoveRight(); } else if (inputHelper.KeyDown(LeftMove) && gameTime.TotalGameTime.Ticks % 6 == 0) { Block.MoveLeft(); } //The next part is about rotating the blocks. if (inputHelper.KeyPressed(RotateCCW)) { TetrisBlock.RotateCounterClockwiseLegit(Block); } else if (inputHelper.KeyPressed(RotateCW)) { TetrisBlock.RotateClockwiseLegit(Block); } //The following part allows the player to move the block down faster. if (inputHelper.KeyDown(GoDown) && gameTime.TotalGameTime.Ticks % 6 == 0) { Block.MoveDown(); ForceBlockDownwards = true; } else { ForceBlockDownwards = false; } if (inputHelper.KeyPressed(SlamDown)) { Block.SlamDown(); } }
public void UpdateBoard(char[,] board, TetrisBlock currentBlock) { var displayBoard = board; if (currentBlock != null) { displayBoard = currentBlock.AddToBoard(board); } var debugTextStr = ""; for (var y = displayBoard.GetLength(1) - 1; y >= 0; y--) { for (var x = 0; x < displayBoard.GetLength(0); x++) { debugTextStr += displayBoard[x, y]; } debugTextStr += "\n"; } debugText.text = debugTextStr; commandText.text = ""; lineCompleteText.text = ""; }
/// <summary> /// Places a block on the grid. /// </summary> public void PlaceBlock() { int random = GameWorld.Random.Next(1, 4); switch (random) { case 1: placeBlock_1.Play(); break; case 2: placeBlock_2.Play(); break; case 3: placeBlock_3.Play(); break; case 4: placeBlock_4.Play(); break; } TetrisBlock block = TetrisGame.gameWorld.activeBlock; for (int x = 0; x < block.block.GetLength(0); x++) { for (int y = 0; y < block.block.GetLength(1); y++) { if (block.block[x, y]) { colorGrid[block.x + x, block.y + y] = block.color; } } } TetrisGame.gameWorld.activeBlock = null; CheckRow(block); }
public void Update(GameTime gameTime) { switch (gameState) { case GameState.Start: MusicPlayer(gameTime); break; case GameState.Playing: blockTimer -= (float)gameTime.ElapsedGameTime.TotalSeconds; if (blockTimer <= 0) { activeBlock.MoveDown(); ResetBlockTimer(); } if (activeBlock == null) { activeBlock = queuedBlock; NewBlock(); if (grid.CheckSpawn(activeBlock)) { GameOver(); } } MusicPlayer(gameTime); break; case GameState.GameMenu: MusicPlayer(gameTime); break; case GameState.GameOver: break; } }
//spawns random block public void Spawn() { switch (nextblock) { case 0: type = new BlockI(); break; case 1: type = new BlockJ(); break; case 2: type = new BlockL(); break; case 3: type = new BlockO(); break; case 4: type = new BlockS(); break; case 5: type = new BlockT(); break; case 6: type = new BlockZ(); break; } //level snelheid aanpassing. type.Basespeed = 40 - (int)score * 2; }
void connectToTankBase(TetrisBlock b) { //if (b.blockType != TetrisBlock.BlockType.Tank) //{ b.blockType = TetrisBlock.BlockType.Tank; for (int dir = 0; dir < 4; dir++) { TetrisBlock neighbor = grid2Block[ direction2Offset[dir, 0] + b.gridCoordX, direction2Offset[dir, 1] + b.gridCoordY ]; if (neighbor != null) { if (neighbor.blockType == TetrisBlock.BlockType.Tank) { neighbor.childBlocks[getOppositeDirectionId(dir)] = b; b.parentBlocks[dir] = neighbor; } } } //} }
public void SetActiveBlock(GameObject block, TetrisBlock tetris) { activeBlock = block; activeTetris = tetris; }
public void SetParent(GameObject _parent) { parent = _parent; parentTetris = parent.GetComponent <TetrisBlock>(); }
public void computeNextIteration() { if (!currentBlock.canMoveTo(grid, currentBlock.computeNextPos(0,1))) { this.grid.add(currentBlock); TetrisBlock blockToAdd = this.nextBlock; if (this.grid.canAdd(blockToAdd)) { currentBlock = this.nextBlock; this.nextBlock = TetrisBlock.generateBlock(); } else { gameOver = true; Console.WriteLine("Game Over"); } } else { currentBlock.translate(0, 1); } }
void GenNewBlock() { this.curBlock = this.nextBlock; this.nextBlock = new TetrisBlock(INIT_ROW, INIT_COL); checkGameOver(); }
void moveBlock2Position (TetrisBlock tmpBlock, int toRow, int toCol) { updateStateByBlock (tmpBlock, 0); tmpBlock.centerRow = toRow; tmpBlock.centerCol = toCol; updateStateByBlock (tmpBlock, 1); }
// Start is called before the first frame update void Start() { instance = this; }
void NewPiece() { if (activeBlocks.Count > 0) { throw new InvalidOperationException("Cannot add new piece at this time"); } TetrisPiece t = TETRIS_VALUES[Random.Range(0, TETRIS_VALUES.Length - 1)]; List<IntVector3> coords = TetrisPieceFactory.NewPiece(t); GameObject templateCube; switch (t) { case TetrisPiece.I: templateCube = iCube; break; case TetrisPiece.J: templateCube = jCube; break; case TetrisPiece.L: templateCube = lCube; break; case TetrisPiece.O: templateCube = oCube; break; case TetrisPiece.S: templateCube = sCube; break; case TetrisPiece.T: templateCube = tCube; break; case TetrisPiece.Z: default: templateCube = zCube; break; } foreach (IntVector3 pt in coords) { TetrisBlock newBlock = new TetrisBlock(templateCube, this, new IntVector3(WIDTH / 2 + pt.x, HEIGHT + HEIGHT_EXTRA + pt.y, LENGTH / 2 + pt.z)); activeBlocks.Add(newBlock); } }
public void Update(GameTime gameTime, TetrisBlock Block) { Clone(Block); SlamDown(); }
// Use this for initialization void Start () { for (int i=0; i<MAX_ROW; i++) { stateArray [i, 0] = 1; stateArray [i, MAX_COL + 1] = 1; } for (int i=0; i<MAX_COL + 1; i++) { stateArray [MAX_ROW, i] = 1; } resetStateArray (); this.ghostBlock = new TetrisBlock (INIT_ROW, INIT_COL); this.nextBlock = new TetrisBlock (INIT_ROW, INIT_COL); GenNewBlock (); lastTime = Time.time; updateStateByBlock (curBlock, 1); }
void TetrisMove() { this.resetFilledYs(); bool isHarddrop = false; bool reactTimeReset = false; if (myTrigger(Buttons.ROTR)) { reactTimeReset |= this.Rotate(this.curBlock.Y, this.curBlock.X, 1); } if (myTrigger(Buttons.ROTL)) { reactTimeReset |= this.Rotate(this.curBlock.Y, this.curBlock.X, -1); } if (myTrigger(Buttons.ROT2)) { reactTimeReset |= this.Rotate(this.curBlock.Y, this.curBlock.X, 2); } if (myTrigger(Buttons.LEFT)) { startDasTime = myTime(); dasDirection = -1; dasStatus = 0; if (!IsCollision(curBlock.Y, curBlock.X - 1, curBlock)) { curBlock.X -= 1; reactTimeReset = true; } } if (myTrigger(Buttons.RIGHT)) { startDasTime = myTime(); dasDirection = 1; dasStatus = 0; if (!IsCollision(curBlock.Y, curBlock.X + 1, curBlock)) { curBlock.X += 1; reactTimeReset = true; } } if (!myButton(Buttons.LEFT) && dasDirection == -1) { dasDirection = 0; } if (!myButton(Buttons.RIGHT) && dasDirection == 1) { dasDirection = 0; } if (dasDirection != 0) { if (dasStatus == 0) { if (myTime() - startDasTime - DAS_TIME >= 0) { if (!IsCollision(curBlock.Y, curBlock.X + dasDirection, curBlock)) { curBlock.X += dasDirection; reactTimeReset = true; startDasTime = myTime(); dasStatus = 1; } } } else { if (myTime() - startDasTime - DAS_REPE >= 0) { if (!IsCollision(curBlock.Y, curBlock.X + dasDirection, curBlock)) { curBlock.X += dasDirection; reactTimeReset = true; startDasTime = myTime(); } } } } if (myTrigger(Buttons.DOWN)) { //toY = curBlock.Y + 1; this.curBlock.Y = this.GetGroundedY(this.curBlock.Y, this.curBlock.X); // Debug.Log ("down:" + isCollision); } if (myTrigger(Buttons.UP)) { this.addScore(this.GetGroundedY(this.curBlock.Y, this.curBlock.X) - this.curBlock.Y); this.curBlock.Y = this.GetGroundedY(this.curBlock.Y, this.curBlock.X); isHarddrop = true; } if (IsGrounded()) { //add immediate react response if (this.isFirstGrounded == false || (this.isFirstGrounded && reactTimeReset)) { this.isFirstGrounded = true; this.startGroundTime = myTime(); } if (isHarddrop || myTime() - this.startGroundTime - REACT_TIME >= 0) { // lock piece updateStateByBlock(this.curBlock, this.curBlock.T); this.curBlock = null; for (int i = 0; i < ghostBlock.listY.GetLength(0); i++) { GameObject.Destroy(this.ghostBlock.blocks[i]); } this.ghostBlock = null; // cleat full lines this.countedFill = this.checkFilledLines(); if (this.countedFill > 0) { for (int Y = 0; Y < MAX_Y; Y++) { if (filledYs[Y] == 1) { for (int X = 0; X < MAX_X; X++) { stateArray[Y, X] = -1; //GameObject.Destroy(blockArray[Y,X],0.0f); // !!!!!!!!!!! 此处把方块推下来砸人 blockArray[Y, X].GetComponent <Rigidbody>().velocity = Vector3.back * (UnityEngine.Random.value * 5 + 2) + Vector3.right * ((UnityEngine.Random.value * 6 - 3) + (X + 0.5f - MAX_X / 2.0f) * 2) + Vector3.up * (UnityEngine.Random.value * 4 + 1); blockArray[Y, X].GetComponent <Rigidbody>().angularVelocity = ( Vector3.back * (UnityEngine.Random.value * 15 - 7) * this.countedFill + Vector3.right * (UnityEngine.Random.value * 15 - 7) * this.countedFill + Vector3.up * (UnityEngine.Random.value * 15 - 7) * this.countedFill ); blockArray[Y, X].GetComponent <Rigidbody>().isKinematic = false; blockArray[Y, X].GetComponent <BoxCollider>().enabled = true; blockArray[Y, X] = null; } } } this.addScore(this.countedFill * this.countedFill * 100); this.noCurClock = true; startAnimationTime = myTime(); GameObject.Find("headCollider").GetComponent <VRCollider>().addLife((float)Math.Pow(this.countedFill, 2) * 0.1f); } else { this.countedFill = 0; GenNewBlock(); } } } else { if (this.FALL_TIME != 0.0f) { this.isFirstGrounded = false; //auto down set download speed if ((myTime() - lastFallTime - FALL_TIME) >= 0) { this.curBlock.Y += 1; lastFallTime = myTime(); } } else { this.curBlock.Y = this.GetGroundedY(this.curBlock.Y, this.curBlock.X); if (reactTimeReset) { startGroundTime = myTime(); } } } }
public void CreateNewBlock() { Debug.Log("Spawning new tetris block"); TetrisBlock newBlock = new TetrisBlock(isAI); newBlock.pos = new TetrisBlock.CoOrd(5, 20); newBlock.CalculateAdditionalPos(); TetrisBlock.CoOrd[] coords = newBlock.GetInhabitedCoords(); for (int i = 0; i < coords.Length; i++) { if (tetris2DMap[coords[i].xCord, coords[i].yCord].cubeInPos) { GameOver(); return; } } activeBlock = newBlock; AIplacedBlock = false; }
public void AddToReserve(TetrisBlock block, int id) { reserve.Add(id, block); }
void moveBlock() { if (activeBlock != null) { bool willCollide = false; TetrisBlock.CoOrd[] coords = activeBlock.GetInhabitedCoords(); for (int i = 0; i < coords.Length; i++) { if (coords[i].yCord <= 0 || (tetris2DMap[coords[i].xCord, coords[i].yCord - 1].cubeInPos && !activeBlock.CheckIfCoOrdInBlock(new TetrisBlock.CoOrd(coords[i].xCord, coords[i].yCord - 1)))) { willCollide = true; } } if (!willCollide) { for (int i = 0; i < coords.Length; i++) { ClearCell(coords[i].xCord, coords[i].yCord); } activeBlock.pos.yCord--; activeBlock.CalculateAdditionalPos(); } else { Debug.Log("active block set to null"); while (checkCompletedLines()) ; activeBlock = null; } } }
void updateStateByBlock (TetrisBlock tmpBlock, int stateVal) { int tmpRow; int tmpCol; Debug.Log ("center row:" + tmpBlock.centerRow + " center col:" + tmpBlock.centerCol); for (int i=0; i < tmpBlock.diffRow.GetLength(0); i++) { tmpRow = tmpBlock.centerRow + tmpBlock.diffRow [i]; tmpCol = tmpBlock.centerCol + tmpBlock.diffCol [i]; if (this.InField (tmpRow, tmpCol)) { stateArray [tmpRow, tmpCol] = stateVal; } } }
public void moveTetrisBlock(int input, ref TetrisBlock activeBlock, Vector2 position) { switch (input) { case 0: //move left if (!checkLeftBoundCollision()) { activeBlock.updateLocation(new Vector2(-1, 0)); } if (checkInternalCollision()) { activeBlock.updateLocation(new Vector2(1, 0)); } break; case 1: //move right if (!checkRightBoundCollision()) { activeBlock.updateLocation(new Vector2(1, 0)); } if (checkInternalCollision()) { activeBlock.updateLocation(new Vector2(-1, 0)); } break; case 2: //move down while (true) { activeBlock.updateLocation(new Vector2(0, 1)); if (checkFallCollision()) { activeBlock.updateLocation(new Vector2(0, -1)); break; } } break; case 3: //rotate right activeBlock.rotateRight(); if (checkInGrid()) { activeBlock.rotateRight(); } activeBlock.rotateRight(); activeBlock.rotateRight(); if (checkInternalCollision()) { activeBlock.rotateRight(); activeBlock.rotateRight(); activeBlock.rotateRight(); } break; case 4: //rotate left activeBlock.rotateRight(); activeBlock.rotateRight(); activeBlock.rotateRight(); if (checkInGrid()) { activeBlock.rotateRight(); } if (checkInternalCollision()) { activeBlock.rotateRight(); } break; case 1000: break; default: break; } if (!checkBlockOnBlockCollision()) { activeBlock.updateLocation(new Vector2(0, 1)); } }
public bool PutBlock(TetrisBlock block, int x, int y, bool canWin) { bool b = false; for (int ix = 0; ix < block.GetBlockWidth(); ix++) { for (int iy = 0; iy < block.GetBlockHeight(); iy++) { int magicY = iy ; if (direction == Direction.LEFT) { magicY = block.GetBlockHeight()-1-iy; } if (block.blocks[magicY, ix] != null) { int ny = iy+y; int nx = ix+x; if (ny < 0 || nx < 0 || nx >= blocks.GetLength(1) || ny >= blocks.GetLength(0)) { if (canWin) { b = true; Fail(); break; } else { return false; } } blocks[iy+y, ix+x] = block.blocks[magicY, ix]; } } if (b) { break; } } float xVal = FieldDefinition.instance.height-y-block.GetBlockHeight()+1; if (direction == Direction.LEFT) { xVal = -(FieldDefinition.instance.height-y); } if (block.GetComponent<PositionTween>() == null) { block.gameObject.AddComponent<PositionTween>(); } block.GetComponent<PositionTween>().TweenTo( new Vector3( xOffset + xVal, x, 0), 0.2f); block.GetComponent<PositionTween>().tweenEndCallback = ScanForLines; return true; }
public TetrisModel(TetrisController controller, TetrisView view) { this.controller = controller; this.view = view; current_block = new TetrisBlock(); }
public void Clone(TetrisBlock Block) //Copies the information from your current block { BlockGrid = Block.BlockGrid; BlockPosition = Block.BlockPosition; }
void GenNewBlock () { this.curBlock = this.nextBlock; this.nextBlock = new TetrisBlock (INIT_ROW, INIT_COL); checkGameOver (); }
//Deze methode voegt objecten toe aan onze Dictionary public void Add(TetrisBlock block, int id) { blocks.Add(id, block); }
public void SpawnNewTetramino() { _tetrisBlock = Instantiate(_tetraminos[UnityEngine.Random.Range(0, _tetraminos.Length)], transform.position, Quaternion.identity); }
bool IsCollision (int targetRow, int targetCol, TetrisBlock tmpBlock) { int tmpRow; int tmpCol; bool result = false; updateStateByBlock (tmpBlock, 0); for (int i = 0; i < 4; i++) { tmpRow = targetRow + tmpBlock.diffRow [i]; tmpCol = targetCol + tmpBlock.diffCol [i]; if (!this.InField (tmpRow, tmpCol) || (stateArray [tmpRow, tmpCol] == 1)) { result = true; } } updateStateByBlock (tmpBlock, 1); return result; }