問題があり、解決方法がわかりません。特定の数のタイルを使用して、XNA アプリ用の 2D マップ エディターを作成する必要があります。マップが 50x100 タイルになるとします。
マップ、タイルに使用するデータ構造と、後でロードするためにハード ドライブに保存する方法がわかりません。
今考えていることはこれです。次のように、マップをテキスト ファイルに保存します。
//x, y, ground_type, object_type
0, 0, 1, 0
0, 1, 2, 1
ここで、0=Grass、1=River etcc (地表)、0=Nothing、1=Wall (オブジェクト タイプ)。
次に、そのファイルを読み取ったり、新しいファイルを最初から作成したりできる Game Component Map クラスを用意します。
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 クラスまたはある種のスーパー マネージャー クラスで処理する必要がありますか?
どんなヒントでも大歓迎です。ありがとう!