-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsolution-shared-edge.ts
29 lines (27 loc) · 984 Bytes
/
solution-shared-edge.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { Tile } from "./tile";
export function generateTiles(tileRows: number, tileColumns: number, tileWidthPixels: number, tileHeightPixels: number): Tile[] {
const tiles: Tile[] = [];
const tileXs: number[] = [];
const tileYs: number[] = [];
// Precoumpute all the x's & y's for the tile geometry
// this keeps us from getting into trouble with floating point math
for (let x = 0; x < (tileColumns + 1); x++) {
tileXs[x] = x * tileWidthPixels;
}
for (let y = 0; y < (tileRows + 1); y++) {
tileYs[y] = y * tileHeightPixels;
}
// Create tile geometry that share the same edges
for (let x = 0; x < tileColumns; x++) {
for (let y = 0; y < tileRows; y++) {
const tile = new Tile({
left: tileXs[x],
right: tileXs[x + 1],
top: tileYs[y],
bottom: tileYs[y + 1]
});
tiles.push(tile);
}
}
return tiles;
}