public OShapeEntity(Game game, string id, Vector2 position, Keys rotate, Keys left, Keys right, Keys down, Vector2 blockSize, Color blockColor) : base(game, id, position, rotate, left, right, down) { BlockEntity block1 = new BlockEntity(Game, "Block", Vector2.Zero, blockColor); BlockEntity block2 = new BlockEntity(Game, "Block", new Vector2(0F, blockSize.Y), blockColor); BlockEntity block3 = new BlockEntity(Game, "Block", new Vector2(blockSize.X, 0F), blockColor); BlockEntity block4 = new BlockEntity(Game, "Block", new Vector2(blockSize.X, blockSize.Y), blockColor); block1.Size = blockSize; block2.Size = blockSize; block3.Size = blockSize; block4.Size = blockSize; AddChild(block1); AddChild(block2); AddChild(block3); AddChild(block4); }
public override void Update(GameTime gameTime) { base.Update(gameTime); // Generate boolean grid BlockEntity[,] grid = new BlockEntity[(int)Dimensions.Y, (int)Dimensions.X]; foreach(ObjectEntity entity in Children) { // Only get blocks (not shapes) if(entity is BlockEntity) { BlockEntity block = entity as BlockEntity; grid[(int)(block.Position.Y / BlockSize.Y), (int)(block.Position.X / BlockSize.X)] = block; } } // Check if there is a full row in the grid for(int row = 0; row < Dimensions.Y; row++) { bool full = true; for(int column = 0; column < Dimensions.X; column++) { if(grid[row, column] == null) { full = false; } } // If the row is full, remove it if(full) { // Add score (Parent as TetrisEntity).Score++; //Add SoundEffect Game.AssetManager.PlaySoundEffect("bottomSound"); for (int column = 0; column < Dimensions.X; column++) { RemoveChild(grid[row, column]); } // Set blocks above the removed row to move for (int moveRow = 0; moveRow < row; moveRow++) { for(int moveColumn = 0; moveColumn < Dimensions.X; moveColumn++) { if(grid[moveRow, moveColumn] != null) { grid[moveRow, moveColumn].Velocity.Y = 1F; grid[moveRow, moveColumn].MoveDownDistance += BlockSize.Y; } } } } } }