this.bunkerGroup = this.physics.add.staticGroup().setDepth(1); const bunkerLocations = [150, 400, 650]; bunkerLocations.forEach(x => { this.createBunker(x, 400); }); createBunker( x: number, y: number) { // バンカーの形をビットマップ形式の配列で定義 (1がブロック、0が空白) const layout = [ [0, 0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 0, 0, 0, 0, 1, 1, 1], [1, 1, 0, 0, 0, 0, 0, 0, 1, 1] ]; const blockSize = 8; // 1つのブロックのサイズ(px) const color = 0x20ff20; // インベーダー風の緑色 // this.bunkerGroup = this.physics.add.staticGroup(); layout.forEach((row, rowIndex) => { row.forEach((value, colIndex) => { if (value === 1) { // 各ドットを矩形(Rectangle)として作成 const block = this.add.rectangle( x + colIndex * blockSize, y + rowIndex * blockSize, blockSize, blockSize, color ); // 物理ボディを有効化 this.bunkerGroup.add(block); } }); }); return this.bunkerGroup; }
bbtest