1

問題があり、解決方法がわかりません。特定の数のタイルを使用して、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 クラスまたはある種のスーパー マネージャー クラスで処理する必要がありますか?

どんなヒントでも大歓迎です。ありがとう!

4

2 に答える 2

1

Why not just store it as:

Height 
Width
GroundType * (Height * Width)

Giving something like

4 
4
0 0 0 0 
0 0 0 0
0 0 0 0
0 0 0 0

It's both easier and more compact. :) As for in-game storage, a 2D array is perfect for this, unless you have other specific needs. A typical collision detection technique is to have a broad phase done by a the physics subsystem, with bounding spheres or axis-aligned bounding boxes for example, and then have the pairs of possibly colliding objects to compute if there was in fact a collision.

Your tile class should probably not be a component, unless you have a very compelling reason.

Edit: Forgot the object type up there, but it'd be easy to integrate it too.

于 2009-04-20T00:27:58.433 に答える
0

ありがとう、でも (ground_type, object_type) のペアを決めました。したがって、次のような入力ファイル

0, 1
0, 0,
0, 0,
1, 1

次のようなマッピングを使用: GROUND = {0:grass, 1:road} OBJECTS = {0:none, 1:crate} および幅 = 2 および高さ = 2 のマップは、次のように生成されます。

grass+crate  |   grass 
grass        |   road+crate

確かに、ファイルを理解するには、マップの幅/高さを知る必要があります。それも入力ファイルに入れるかもしれません。

于 2009-04-20T19:08:33.840 に答える