public bool NoCollision() { for (int h = blockHeight - 1; h >= 0; h--) { for (int j = 0; j < blockWidth; j++) { if (block.curBool[h, j] && block.Location.Y + h + 1 >= grid.Height) { AddBlock(blockWidth, blockHeight); block = block.GetRandomBlock(random.Next(0, 7)); //block = new BlockI(new Vector2(4, -4)); update = true; return(false); } if (block.Location.Y + h >= 0 && block.Location.X - LeftClear() + j >= 0 && block.Location.Y + h + 1 <= grid.Height && block.Location.X + j <= grid.Width) //alleen de waardes binnen de grid moeten worden gecheckt { if (block.curBool[h, j] && grid.grid[(int)block.Location.Y + h + 1, (int)block.Location.X + j]) { AddBlock(blockWidth, blockHeight); block = block.GetRandomBlock(random.Next(0, 7)); //block = new BlockI(new Vector2(4, -4)); update = true; return(false); } } } } return(true); }
void BlockUpdate() { AddBlock(block.blockSize, block.blockSize); LineFull(); block = nextBlock; nextBlock = block.GetRandomBlock(random.Next(0, 7)); hold = true; }
public void DrawBlocks(SpriteBatch spriteBatch, TetrisBlocks block) { for (int a = 0; a < blockHeight; a++) { for (int b = 0; b < blockWidth; b++) { if (block.curBool[a, b] && a >= 0 && b >= 0 && a <= grid.Height && b <= grid.Width) { spriteBatch.Draw(grid.emptyCell, new Vector2((b + block.Location.X) * grid.emptyCell.Width, (a + block.Location.Y) * grid.emptyCell.Height), block.curColor); } } } }
public GameWorld() { random = new Random(); gameState = GameState.Playing; font = TetrisGame.ContentManager.Load <SpriteFont>("SpelFont"); speed = 15; grid = new TetrisGrid(); block = block.GetRandomBlock(random.Next(0, 7)); //block = new BlockI(new Vector2(4, -4)); blockWidth = block.curBool.GetLength(1); blockHeight = block.curBool.GetLength(0); blockList = new List <TetrisBlocks>(); }
public void Reset() { for (int x = 0; x < grid.Width; x++) { for (int y = 0; y < grid.Height; y++) { grid.grid[y, x] = null; } } score = 0; speed = 15; level = 1; block = block.GetRandomBlock(random.Next(0, 7)); nextBlock = block.GetRandomBlock(random.Next(0, 7)); }
public void HandleInput(GameTime gameTime, InputHelper inputHelper) { if (gameState == GameState.Title) { if (inputHelper.MouseLeftButtonPressed()) { gameState = GameState.Playing; } } if (gameState == GameState.GameOver) { if (inputHelper.MouseLeftButtonPressed()) { gameState = GameState.Title; } } if (gameState == GameState.Playing) { if (inputHelper.KeyPressed(Keys.Left)) { if (block.Location.X > 0 - LeftClear() && CanGoLeft()) block.Location.X--; if (!NoCollision()) grid.tijd = 0; } if (inputHelper.KeyPressed(Keys.Right)) { if (block.Location.X + block.blockSize < grid.Width + RightClear() && CanGoRight()) block.Location.X++; if (!NoCollision()) grid.tijd = 0; } if (inputHelper.KeyPressed(Keys.Space)) { while (NoCollision()) { block.Location.Y += 1; } space = true; } if (inputHelper.KeyPressed(Keys.A)) { MoveIfBlocked(); if (CanGoLeft() && CanGoRight()) block.curBool = Rotate(block.curBool, false, block.blockSize); if (!NoCollision()) grid.tijd = 0; } if (inputHelper.KeyPressed(Keys.D)) { MoveIfBlocked(); if (CanGoLeft() && CanGoRight()) block.curBool = Rotate(block.curBool, true, block.blockSize); if (!NoCollision()) grid.tijd = 0; } if (inputHelper.KeyPressed(Keys.C)) { if (holdBlock == null) { holdBlock = block; block = nextBlock; nextBlock = block.GetRandomBlock(random.Next(0, 7)); block.Location = block.SpawnLocation; } if (hold) { saveBlock = block; block = holdBlock; holdBlock = saveBlock; block.Location = block.SpawnLocation; hold = false; } } } }