コード例 #1
0
ファイル: HexGrid.js プロジェクト: cnatis/game-engine
	generate: function(params) {
		if(isNone(params)) {
			params = {};
		}
		this.size = withDefault(params.size, this.size);
		let x, y, z;
		for (x = -this.size; x < this.size + 1; x++) {
			for (y = -this.size; y < this.size + 1; y++) {
				z = -x-y;
				if (Math.abs(x) <= this.size && Math.abs(y) <= this.size && Math.abs(z) <= this.size) {
					// Create a hexCell for the position in the grid
					let c = HexCell({
						q: x, 
						r: y, 
						s: z,
						hashDelimeter: this.hashDelimeter,
						size: this.cellSize
					});
					let t = Tile({
						cell: c,
						material: params.material
					});
					this.add(c);
				}
			}
		}
	},
コード例 #2
0
ファイル: HexGrid.js プロジェクト: cnatis/game-engine
export function HexGrid(params) {
	if(isNone(params)) {
		params = {};
	}
    let hexGrid = {
    	cellSize: withDefault(params.cellSize, 10),
    	cells: {},
    	hashDelimeter: withDefault(params.hashDelimeter, '-')
    };
    
    // pre-computed permutations
	hexGrid._directions = [
		HexCell({
			q: +1, 
			r: -1, 
			s: 0,
			size: hexGrid.cellSize
		}), 
		HexCell({
			q: +1, 
			r: 0, 
			s: -1,
			size: hexGrid.cellSize
		}), 
		HexCell({
			q: 0, 
			r: +1, 
			s: -1,
			size: hexGrid.cellSize
		}),				
		HexCell({
			q: -1, 
			r: +1, 
			s: 0,
			size: hexGrid.cellSize
		}), 
		HexCell({
			q: -1, 
			r: 0, 
			s: +1,
			size: hexGrid.cellSize
		}),
		HexCell({
			q: 0, 
			r: -1, 
			s: +1,
			size: hexGrid.cellSize
		})
	];
	// this._diagonals = [HexCell(+2, -1, -1), HexCell(+1, +1, -2), HexCell(-1, +2, -1),
	// 				   HexCell(-2, +1, +1), HexCell(-1, -1, +2), HexCell(+1, -2, +1)];
    
	// cached objects
	hexGrid._list = [];
	hexGrid._vec3 = new THREE.Vector3();
	hexGrid._cell = HexCell({
		q: 0, 
		r: 0, 
		s: 0,
		hashDelimeter: hexGrid.hashDelimeter,
		size: hexGrid.cellSize
	});
	hexGrid._conversionVec = new THREE.Vector3();
	hexGrid._geoCache = [];
	hexGrid._matCache = [];
    
    return extend(hexGrid, hexGridUtils);
};