/// <summary> /// Draw the current queue /// </summary> /// <param name="spriteBatch"></param> private void DrawQueue(SpriteBatch spriteBatch) { const int blockSize = TetrisGame.BlockSize; // Draw first shape in queue BaseShape firstShape = ShapesQueue.Peek(); float scale = 0.85f; Screen.Board.DrawShape(spriteBatch, firstShape, new Vector2( Screen.Board.Bounds.Right - firstShape.Bounds.X * blockSize * scale + 21 + 60 - firstShape.Origin.X * scale, TetrisGame.BoardPaddingTop - firstShape.Bounds.Y * blockSize * scale + 74 + 60 - firstShape.Origin.Y * scale), scale); // Draw the rest const int queueAreaWidth = 47; const int queueAreaHeight = 49; float offsetY = 0f; scale = 0.65f; int i = 0; foreach (var shape in ShapesQueue) { i++; // Skip the first shape if (i == 1) { continue; } Vector2 pos = new Vector2( Screen.Board.Bounds.Right - shape.Bounds.X * blockSize * scale + 34 + queueAreaWidth - shape.Origin.X * scale, TetrisGame.BoardPaddingTop + offsetY - shape.Bounds.Y * blockSize * scale + 236 + queueAreaHeight - shape.Origin.Y * scale); Screen.Board.DrawShape(spriteBatch, shape, pos, scale); offsetY += queueAreaHeight * 2; } }
/// <summary> /// Spawns the next shape in queue or use the provided `shape`. /// </summary> public void SpawnShape(BaseShape shape = null) { // Fill the queue if needed while (ShapesQueue.Count < MaxShapesInQueue) { ShapesQueue.Enqueue(ShapesFactory.CreateShape(Screen.BlockTexture, Screen.Board, (ShapeTypes)_random.Next(7))); } if (shape == null) { shape = ShapesQueue.Dequeue(); } shape.Position = new Vector2(3, 1); Shape = shape; if (ShapesQueue.Count < MaxShapesInQueue) { shape = ShapesFactory.CreateShape(Screen.BlockTexture, Screen.Board, (ShapeTypes)_random.Next(7)); ShapesQueue.Enqueue(shape); } }