//----------------------------------------------------------------------------- // DeckDisplayComponent.cs // // Displays a visual representation of the card deck during gameplay //----------------------------------------------------------------------------- using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; namespace CardsFramework { /// /// Component that displays a visual representation of the deck at the dealer position. /// Shows a stack of card backs to indicate where cards are being dealt from. /// public class DeckDisplayComponent : DrawableGameComponent { private readonly CardsGame cardGame; private readonly SpriteBatch spriteBatch; private readonly Matrix globalTransformation; private readonly Vector2 position; private Texture2D cardBackTexture; /// /// Number of card back layers to draw for the stacked effect /// public int StackLayers { get; set; } = 3; /// /// Offset between each layer to create depth /// public Vector2 LayerOffset { get; set; } = new Vector2(1, 1); /// /// Rotation angle in radians (default -45 degrees / clockwise for casino look) /// public float Rotation { get; set; } = MathHelper.ToRadians(-45); /// /// Whether the deck should be visible /// public new bool Visible { get; set; } = true; /// /// Creates a new deck display component /// /// The game instance /// The card game instance /// Position where the deck should be displayed /// Shared sprite batch for rendering /// Transformation matrix for scaling public DeckDisplayComponent( Game game, CardsGame cardGame, Vector2 position, SpriteBatch spriteBatch, Matrix globalTransformation) : base(game) { this.cardGame = cardGame; this.position = position; this.spriteBatch = spriteBatch; this.globalTransformation = globalTransformation; DrawOrder = -5000; // Draw behind dealt cards but in front of table } /// /// Load the card back texture /// protected override void LoadContent() { base.LoadContent(); // Get the card back texture from the card game's assets if (cardGame.cardsAssets.ContainsKey("CardBack_" + cardGame.Theme)) { cardBackTexture = cardGame.cardsAssets["CardBack_" + cardGame.Theme]; } } /// /// Draw the deck as a stack of card backs /// public override void Draw(GameTime gameTime) { if (!Visible || cardBackTexture == null) return; spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, globalTransformation); // Calculate origin point for rotation (center of the card) Vector2 origin = new Vector2(cardBackTexture.Width / 2f, cardBackTexture.Height / 2f); // Draw multiple layers to create a stacked deck effect for (int i = 0; i < StackLayers; i++) { Vector2 layerPosition = position + (LayerOffset * i); // Draw with slight transparency on lower layers for depth float alpha = 1.0f - (i * 0.1f); Color color = Color.White * alpha; // Draw with rotation around the center origin spriteBatch.Draw(cardBackTexture, layerPosition, null, color, Rotation, origin, 1.0f, SpriteEffects.None, 0f); } spriteBatch.End(); base.Draw(gameTime); } } }