public void Draw(DrawContext ctx, GamePane pane, float alpha) { Color4 blockColor = color; blockColor.A = alpha; ctx.BindTexture(texture); ctx.SetColor(blockColor); ctx.DrawTexturedRectangle(pane.BlockSize, pane.BlockSize, texture); }
public void Draw(DrawContext ctx) { List<GameBlockState> deferredBlocks = new List<GameBlockState>(); float scale = 1.0f + (float)Math.Sin(jitter * 0.5f) * 0.003f; float angle = (float)Math.Sin(jitter * 0.5) * 0.15f; ctx.Push(); ctx.Translate(position.X, position.Y); ctx.ScaleAroundPoint(scale, scale, Columns * BlockSize / 2, Rows * BlockSize / 2); ctx.RotateAroundPoint(angle, Columns * BlockSize / 3, Rows * BlockSize / 3); // cursor if (!gameOver) { ctx.Push(); ctx.Translate(GetBlockX(cursorColumn) - 4, GetBlockY(cursorRow) - 4); ctx.BindTexture(cursorTexture); ctx.SetColor(new Color4(100, 100, 100, 255)); ctx.DrawTexturedRectangle(BlockSize * 2.0f + 8, BlockSize + 8, cursorTexture); ctx.Pop(); // game over logo } else { ctx.Push(); ctx.Translate(40.0f, 240.0f); ctx.BindTexture(session.GameOverTexture); ctx.DrawTexturedRectangle(240.0f, 45.0f, session.GameOverTexture); ctx.Pop(); } // regular blocks for (int column = 0; column < Columns; column++) { for (int row = 0; row < Rows; row++) { GameBlockState blockState = this[column, row]; if (blockState.Empty) continue; if (blockState.DrawDeferred) deferredBlocks.Add(blockState); else blockState.Draw(ctx); } } // block independent block animations foreach (GameBlockAnimation animation in activeAnimations) animation.Draw(ctx); // top and bottom bars that hide partial rows if (!gameOver) { ctx.Push(); ctx.BindTexture(session.BarTexture); ctx.SetColor(new Color4(40, 40, 40, 255)); ctx.Translate(-BlockSize / 2, -35.0f); ctx.DrawTexturedRectangle(BlockSize * (Columns + 1), 40.0f, session.BarTexture); ctx.Translate(0.0f, BlockSize * Rows - BlockSize / 2); ctx.DrawTexturedRectangle(BlockSize * (Columns + 1), 50.0f, session.BarTexture); ctx.Pop(); } // selected blocks and other things we want to have on top foreach (GameBlockState blockState in deferredBlocks) blockState.Draw(ctx); ctx.Pop(); }
public void Draw(DrawContext ctx) { List <GameBlockState> deferredBlocks = new List <GameBlockState>(); float scale = 1.0f + (float)Math.Sin(jitter * 0.5f) * 0.003f; float angle = (float)Math.Sin(jitter * 0.5) * 0.15f; ctx.Push(); ctx.Translate(position.X, position.Y); ctx.ScaleAroundPoint(scale, scale, Columns * BlockSize / 2, Rows * BlockSize / 2); ctx.RotateAroundPoint(angle, Columns * BlockSize / 3, Rows * BlockSize / 3); // cursor if (!gameOver) { ctx.Push(); ctx.Translate(GetBlockX(cursorColumn) - 4, GetBlockY(cursorRow) - 4); ctx.BindTexture(cursorTexture); ctx.SetColor(new Color4(100, 100, 100, 255)); ctx.DrawTexturedRectangle(BlockSize * 2.0f + 8, BlockSize + 8, cursorTexture); ctx.Pop(); // game over logo } else { ctx.Push(); ctx.Translate(40.0f, 240.0f); ctx.BindTexture(session.GameOverTexture); ctx.DrawTexturedRectangle(240.0f, 45.0f, session.GameOverTexture); ctx.Pop(); } // regular blocks for (int column = 0; column < Columns; column++) { for (int row = 0; row < Rows; row++) { GameBlockState blockState = this[column, row]; if (blockState.Empty) { continue; } if (blockState.DrawDeferred) { deferredBlocks.Add(blockState); } else { blockState.Draw(ctx); } } } // block independent block animations foreach (GameBlockAnimation animation in activeAnimations) { animation.Draw(ctx); } // top and bottom bars that hide partial rows if (!gameOver) { ctx.Push(); ctx.BindTexture(session.BarTexture); ctx.SetColor(new Color4(40, 40, 40, 255)); ctx.Translate(-BlockSize / 2, -35.0f); ctx.DrawTexturedRectangle(BlockSize * (Columns + 1), 40.0f, session.BarTexture); ctx.Translate(0.0f, BlockSize * Rows - BlockSize / 2); ctx.DrawTexturedRectangle(BlockSize * (Columns + 1), 50.0f, session.BarTexture); ctx.Pop(); } // selected blocks and other things we want to have on top foreach (GameBlockState blockState in deferredBlocks) { blockState.Draw(ctx); } ctx.Pop(); }