如何使用 C# 在 XNA 中创建俄罗斯方块块?
我正在使用 XNA 用 C# 制作俄罗斯方块克隆,但我不确定如何实际实现这些块。
我不认为将形状制作为图像会起作用(因为形成线条时部分会被删除),所以我有块来组成像 这个。
不幸的是,我不知道如何实际定义块来制作碎片,也不知道如何操纵它们以使它们旋转等。
编辑:我还需要帮助来学习如何制作俄罗斯方块网格。
I'm making a Tetris Clone in C# with XNA, and I'm unsure of how to actually implement the blocks.
I don't think that making the shapes as images will work (because parts are removed when lines are formed), so I Have blocks to make up the pieces like This.
Unfortunately, I don't know how to actually define the blocks to make the pieces, nor do I know how to manipulate them to make them rotate, etc.
Edit: I would also need assistance in learning how to make the Tetris Grid too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我以前没有创建过俄罗斯方块,但经过一番思考,我相信我会使用一个简单的矩阵来创建我的作品。例如,您的整个游戏板将是一个大矩阵。该矩阵的一个子集(例如 4x4 块)将是一个游戏块。该 4x4 块的哪些部分将被填充将取决于您要创建的特定块。矩阵的每个部分都可以有一个布尔标志,指示它是否已填充。这是一个非常简单的观点,但我认为这是一个可行的解决方案。
I haven't created tetris before, but after some thinking, I believe that I would use a simple matrix to create my pieces. For example, your whole game board would be one big matrix. A subset of that matrix, say a 4x4 block of it, would be a game piece. Which parts of that 4x4 block would be filled would be determined by which particular piece you want to create. Each part of the matrix can have a boolean flag that would indicate if it's filled or not. This is a very simplistic view of it, but I think it's a viable solution.
使用布尔矩阵对屏幕状态进行建模。每个部分本身就是另一个较小的布尔矩阵。
旋转一块就像稍微调整一下坐标一样简单(我把这个留给你了)。
关于如何渲染,只需为矩阵中的每个真实值绘制一个块,并移动和旋转当前下落的块即可。
Use a boolean matrix to model the state of the screen. Each piece is itself another smaller boolean matrix.
Rotating a piece is as simple as playing with the coordinates a little bit (I left this to you).
About how to render, just draw a piece tile for each true value in your matrix
ored
with the current falling piece shifted and rotated.对于块,我强烈建议以 3D 方式工作。您仍然可以通过锁定相机等方式使游戏看起来像 2D,但您将从矢量图形中受益匪浅。您的块将是简单的立方体(平坦或具有一定深度),您可以在屏幕上旋转和移动它们。
对于网格,请查看@fortran 和@aaron 的答案,布尔矩阵即可解决问题。
For the blocks, I would strongly suggest working in 3D. You can still make the game look like 2D by locking the camera etc, but you will benefit a lot from working in vector graphics. Your blocks will be simple cubes (flat or with some depth) that you rotate and move around the screen.
For the grid, look at @fortran's and @aaron's answers, a boolean matrix will do the trick.
也许此链接到 Coding4Fun 会有所帮助。它是德语的,但您应该能够获取源代码并看看问题是如何解决的。
可以肯定的是,这里的 直接下载链接。
Maybe this link to Coding4Fun will help. It's in german, but you should be able to get the source code and take a look on how about the problem is solved here.
Just to be sure, here the direct download link.