如何绘制方块的俄罗斯方块

本文关键字:方块 俄罗斯 绘制 何绘制 | 更新日期: 2023-09-27 18:17:15

我正在制作俄罗斯方块,我不知道如何绘制方块(L,I,Z等)我有一个方块作为Texture2D,每个方块的类看起来像这样:

namespace Tetris
{
    public class ZBlock
    {
        Color Color;
        const int x = 4;
        const int y = 4;
        bool[,] vorm;
        public bool[,] zblock()
        {
            vorm = new bool[x, y];
            for(int i=0; i< x; i++)
                for (int j=0; j<y; j++)
                {
                    vorm[i, j] = false;
                    vorm[0, 0] = true;
                    vorm[1, 0] = true;
                    vorm[1, 1] = true;
                    vorm[2, 1] = true;
                }
            Color = Color.Purple;
            return vorm;
        }
    }

这是block类:

namespace Tetris
{
    public class Block
    {
        Texture2D block;
        Vector2 BlockPosition = new Vector2(30, 30);
        float FallTimer;
        Random Random = new Random();
        ZBlock zBlock = new ZBlock();
        TBlock tBlock = new TBlock();
        SBlock sBlock = new SBlock();
        OBlock oBlock = new OBlock();
        JBlock jBlock = new JBlock();
        LBlock lBlock = new LBlock();
        IBlock iblock = new IBlock();
        public bool[,] blockvorm()
        {
            bool[,] vorm;
            vorm = new bool[4, 4];
            vorm[3, 3] = false;
            int r = Random.Next(7);
            if (r == 0)
            {
                ZBlock.zblock();
            }
            else if (r == 1)
            {
                TBlock.tblock();
            }
            else if (r == 2)
            {
                SBlock.sblock();
            }
            else if (r == 3)
            {
                OBlock.oblock();
            }
            else if (r == 4)
            {
                JBlock.jblock();
            }
            else if (r == 5)
            {
                LBlock.lblock();
            }
            else if (r == 6)
            {
                IBlock.iblock();
            }
            return vorm;
        }
        public TBlock TBlock
        {
            get { return tBlock; }
        }
        public ZBlock ZBlock
        {
            get { return zBlock; }
        }
        public SBlock SBlock
        {
            get { return sBlock; }
        }
        public OBlock OBlock
        {
            get { return oBlock; }
        }
        public JBlock JBlock
        {
            get { return jBlock; }
        }
        public LBlock LBlock
        {
            get { return lBlock; }
        }
        public IBlock IBlock
        {
            get { return iblock; }
        }
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, ContentManager Content)
        {
            block = Content.Load<Texture2D>("Block");
            int[,] Grid = Tetris.GameWorld.TetrisGrid;
            spriteBatch.Begin();
            spriteBatch.Draw(?????????????);
            spriteBatch.End();
        }

所以问题是:我不知道如何绘制这些块(我知道如何绘制一个块,但我想要完整的)。我想可能是ZBlock.vormZBLock.zblock,但两者都给出错误。

有谁知道怎么画积木吗?

如何绘制方块的俄罗斯方块

好的,这是部分答案。你要做的基本上只是绘制每个块与下一个块的一定偏移量等于:blockWidth / 2像素。这意味着块将正确定向,没有重叠。

下面是你应该在draw语句中输入的内容:

public void Draw(int theXPosition, int theYPosition, Color theColor, SpriteBatch theSpriteBatch, Texture2D theBlockTexture)
{
    int aTextureStartX = Color * Convert.ToInt32(mBlockSize);
    for (int aBlock = 0; aBlock < mNumberOfBlocks; aBlock++)
    {
            int aXPosition = (int)(theXPosition + (CurrentShape[Rotation, aBlock, 0] * mBlockSize));
            int aYPosition = (int)(theYPosition + (CurrentShape[Rotation, aBlock, 1] * mBlockSize));
            theSpriteBatch.Draw(theBlockTexture, new Rectangle(aXPosition, aYPosition, mBlockSize, mBlockSize), new Rectangle(aTextureStartX, 0, mBlockSize, mBlockSize), 
    }
}

这是来自一个博客:http://www.xnadevelopment.com/tutorials/fallingblocksyoumovetomakelines/fallingblocksyoumovetomakelines.shtml

源代码在页面的顶部