Skip to content

地形配列(Dungeon Matrix)

Kasuga Chiyo edited this page Mar 3, 2019 · 5 revisions

地形配列(Dungeon Matrix)

ダンジョンの地形データを格納する配列。 多くの場合、STLを使用する。

記事ではmatrixという名前で宣言する。

また、引数に使用する場合はmatrix_という名前が使われる。

使用方法

固定長配列の宣言例

横(X軸方向)のサイズがdungeon_size_x、縦(Y軸方向)のサイズがdungeon_size_y、 変数型がdungeon_tの地形配列を作成。

std::array<std::array<dungeon_t, dungeon_size_x>, dungeon_size_y> matrix{ {} };

可変長配列の宣言例

横(X軸方向)のサイズがdungeon_size_x、縦(Y軸方向)のサイズがdungeon_size_y、 変数型がdungeon_tの地形配列を作成。

std::vector<std::vector<dungeon_t>> matrix(dungeon_size_y, std::vector<dungeon_t>(dungeon_size_x, 0));

値を代入する例

横(X軸方向)の位置がx、縦(Y軸方向)の位置がyの場所に0を代入する。

matrix[y][x] = 0;
Clone this wiki locally