我正在尝试制作一个"dungeon crawler"类型的游戏演示,这是我第一次真正做出Pong和Pac-Man克隆以外的任何东西.我现在最大的悬念是创造实际水平.我已经完成了如何在屏幕上绘制瓷砖的教程,但我找不到任何关于从那里去的地方.
如何从一个屏幕转到制作一个更大的地牢?任何帮助表示赞赏.
您应该考虑使用二维数组开始.通过这种方式,您可以非常轻松地直观地表示数据.
从初始化开始:
//2D array
int[,] array;
Run Code Online (Sandbox Code Playgroud)
一些样本数据:
array= new int[,]
{
{0, 2, 2, 0},
{3, 0, 0, 3},
{1, 1, 1, 1},
{1, 0, 0, 0},
};
Run Code Online (Sandbox Code Playgroud)
创建一个枚举,它将索引地图中的每个整数:
enum Tiles
{
Undefined = 0,
Dirt = 1,
Water = 2,
Rock = 3
}
Run Code Online (Sandbox Code Playgroud)
然后加载纹理,而不是通过一次查看一个项目的数组.根据您的纹理大小,您可以在地图上显示的屏幕上轻松绘制纹理:
for (int i = 0; i < array.Count; i++)
{
for (int j = 0; j < array[0].Count; j++) //assuming always 1 row
{
if (array[i][j] == (int)Tiles.Undefined) continue;
Texture = GetTexture(array[i][j]); //implement this
spriteBatch.Draw(Texture, new Vector2(i * Texture.Width, j * Texture.Height), null, Color.White, 0, Origin, 1.0f, SpriteEffects.None, 0f);
}
}
Run Code Online (Sandbox Code Playgroud)