我有一个问题,我不知道如何处理解决方案。 我需要为我的XNA应用程序创建2D地图编辑器,并添加一定数量的图块。 说一个地图将是50x100的瓷砖。XNA如何存储和绘制2D地图?
我不确定什么数据结构用于地图,瓷砖以及如何将它存储在硬盘上供以后加载。
我现在的想法是这样的。我将地图存储在文本文件中,像这样:
//x, y, ground_type, object_type
0, 0, 1, 0
0, 1, 2, 1
其中0 =草,1 =河ETCC地面地形,和0 =无,1 =墙对象类型。
然后,我将有一个可以读取该文件或者从头开始创建一个新的一个游戏组件地图类:
class Map : DrawableGameComponent {
//These are things like grass, whater, sand...
Tile ground_tiles[,];
//These are things like walls that can be destroyed
Tile object_tiles[,];
public Map(Game game, String filepath){
for line in open(filepath){
//Set the x,y tile to a new tile
ground_tiles[line[0], line[1]] = new Tile(line[3])
object_tiles[line[0], line[1]] = new Tile(line[4])
}
}
public Map(Game game, int width, int heigth){
//constructor
init_map()
}
private void init_map(){
//initialize all the ground_tiles
//to "grass"
for i,j width, heigth{
ground_tiles[i,j] = new Tile(TILE.GRASS)
}
public override Draw(game_time){
for tile in tiles:
sprite_batch.draw(tile.texture, tile.x, tile.y etc..)
}
我的瓷砖类可能不会是一个游戏组件。 我仍然不确定如何处理来自玩家的子弹与地图对象之间的碰撞检测。是否应该由Map类或某种超级Manager类来处理?
欢迎任何提示。 谢谢!