我有一个问题,我不确定如何解决。我需要为我的 XNA 应用程序创建一个 2D 地图编辑器,其中包含一定数量的图块。假设地图将是 50x100 的图块。
我不确定地图、图块使用什么数据结构以及如何将其存储在硬盘驱动器上以供以后加载。
我现在想的是这个。我会将地图存储在一个文本文件中,如下所示:
//x, y, ground_type, object_type
0, 0, 1, 0
0, 1, 2, 1
其中 0 = 草,1 = 河流等地面地形,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..)
}
我的 Tile 类可能不是游戏组件。我仍然不太确定如何处理碰撞检测,例如来自玩家的子弹与地图对象之间的碰撞检测。这应该由 Map 类还是某种超级 Manager 类来处理?
欢迎任何提示。谢谢!