forked from maticstric/WebGL-Breakout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTileGrid.js
104 lines (74 loc) · 2.7 KB
/
TileGrid.js
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
class TileGrid {
static get WALL_X() {return 9;}
static get WALL_Y() {return 10.1;}
static get WALL_RADIUS() {return 0.5;}
static get eastEdge(){return TileGrid.WALL_X - TileGrid.WALL_RADIUS;}
static get westEdge(){return -TileGrid.WALL_X + TileGrid.WALL_RADIUS;}
static generateLevel1(rows, cols, margin) {
let tiles = [];
for (let r = 0; r < rows; r++) {
for (let c = 0; c < cols; c++) {
let t = new Tile();
let width = t.width;
let height = t.height;
let x = -(margin * ((cols - 1) / 2) + width * ((cols - 1) / 2)) + c * (width + margin);
let y = -(margin * ((rows - 1) / 2) + height * ((rows - 1) / 2)) + r * (height + margin);
let z = 0;
t.model.positionMatrix.translate(x, y, z);
tiles.push(t);
}
}
g_tilesOriginalLength = tiles.length;
return tiles;
}
static generateLevel2(rows, cols, margin) {
let tiles = [];
for (let r = 0; r < rows; r += 2) {
for (let c = 0; c < cols; c++) {
let t = new Tile();
let width = t.width;
let height = t.height;
let x = -(margin * ((cols - 1) / 2) + width * ((cols - 1) / 2)) + c * (width + margin);
let y = -(margin * ((rows - 1) / 2) + height * ((rows - 1) / 2)) + r * (height + margin);
let z = 0;
t.model.positionMatrix.translate(x, y, z);
tiles.push(t);
}
}
g_tilesOriginalLength = tiles.length;
return tiles;
}
static generateLevel3(rows, cols, margin) {
let tiles = [];
for (let r = 0; r < rows; r += 2) {
for (let c = 0; c < cols; c += 2) {
let t = new Tile();
let width = t.width;
let height = t.height;
let x = -(margin * ((cols - 1) / 2) + width * ((cols - 1) / 2)) + c * (width + margin);
let y = -(margin * ((rows - 1) / 2) + height * ((rows - 1) / 2)) + r * (height + margin);
let z = 0;
t.model.positionMatrix.translate(x, y, z);
tiles.push(t);
}
}
g_tilesOriginalLength = tiles.length;
return tiles;
}
static generateWalls() {
let west = new Wall();
let north = new Wall();
let east = new Wall();
// We'll probably adjust all these numbers later
west.scale(TileGrid.WALL_RADIUS, TileGrid.WALL_Y + TileGrid.WALL_RADIUS,
TileGrid.WALL_RADIUS);
north.scale(TileGrid.WALL_X + TileGrid.WALL_RADIUS, TileGrid.WALL_RADIUS,
TileGrid.WALL_RADIUS);
east.scale(TileGrid.WALL_RADIUS, TileGrid.WALL_Y + TileGrid.WALL_RADIUS,
TileGrid.WALL_RADIUS);
west.translate(-TileGrid.WALL_X, 0, 0);
north.translate(0, TileGrid.WALL_Y, 0);
east.translate(TileGrid.WALL_X, 0, 0);
return [west, north, east];
}
}