-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
237 lines (209 loc) · 7.21 KB
/
app.js
File metadata and controls
237 lines (209 loc) · 7.21 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
window.onload =
function App() {
const tiles = 6;
const tileSize = 100; // px per tile (24 inches)
const fieldOffsetX = 80;
const fieldOffsetY = 80;
const pxPerInch = tileSize / 24;
const blue = '#2563eb';
const red = '#ef4444';
const purple = '#9333ea';
const green = '#16a34a';
const svg = document.getElementById("fieldSVG");
function tileTopLeft(x, y) {
const sx = fieldOffsetX + x * tileSize;
const sy = fieldOffsetY + (tiles - 1 - y) * tileSize;
return { sx, sy };
}
function drawGrid() {
for (let i = 0; i <= tiles; i++) {
let x = fieldOffsetX + i * tileSize;
svg.appendChild(newLine(x, fieldOffsetY, x, fieldOffsetY + tiles * tileSize, "#94a3b8"));
let y = fieldOffsetY + i * tileSize;
svg.appendChild(newLine(fieldOffsetX, y, fieldOffsetX + tiles * tileSize, y, "#94a3b8"));
}
}
function newLine(x1, y1, x2, y2, stroke, width = 2) {
let l = document.createElementNS("http://www.w3.org/2000/svg", "line");
l.setAttribute("x1", x1);
l.setAttribute("y1", y1);
l.setAttribute("x2", x2);
l.setAttribute("y2", y2);
l.setAttribute("stroke", stroke);
l.setAttribute("stroke-width", width);
return l;
}
function newRect(x, y, w, h, fill, stroke, width = 2) {
let r = document.createElementNS("http://www.w3.org/2000/svg", "rect");
r.setAttribute("x", x);
r.setAttribute("y", y);
r.setAttribute("width", w);
r.setAttribute("height", h);
if (fill) r.setAttribute("fill", fill);
else r.setAttribute("fill", "none");
if (stroke) {
r.setAttribute("stroke", stroke);
r.setAttribute("stroke-width", width);
}
return r;
}
function newCircle(cx, cy, r, fill, stroke) {
let c = document.createElementNS("http://www.w3.org/2000/svg", "circle");
c.setAttribute("cx", cx);
c.setAttribute("cy", cy);
c.setAttribute("r", r);
if (fill) c.setAttribute("fill", fill);
if (stroke) c.setAttribute("stroke", stroke);
return c;
}
function newPolygon(points, fill, stroke, width = 2) {
let p = document.createElementNS("http://www.w3.org/2000/svg", "polygon");
p.setAttribute("points", points.map(pt => pt.join(",")).join(" "));
if (fill) p.setAttribute("fill", fill);
else p.setAttribute("fill", "none");
if (stroke) {
p.setAttribute("stroke", stroke);
p.setAttribute("stroke-width", width);
}
return p;
}
// === Field Elements ===
function drawGoalTriangle(x, y, color, side) {
const { sx, sy } = tileTopLeft(x, y);
if (side === "blue") {
let pts = [
[sx, sy],
[sx + tileSize, sy],
[sx, sy + tileSize],
];
svg.appendChild(newPolygon(pts, "none", color, 4));
} else {
let pts = [
[sx, sy],
[sx + tileSize, sy],
[sx + tileSize, sy + tileSize],
];
svg.appendChild(newPolygon(pts, "none", color, 4));
}
}
function drawRamp(x, y, color, direction) {
const rampWidth = 6 * pxPerInch;
const rampLen = 2 * tileSize;
const { sx, sy } = tileTopLeft(x, y);
let pts;
if (direction === "down-left") {
pts = [
[sx, sy + tileSize],
[sx + rampWidth, sy + tileSize],
[sx + rampWidth, sy + tileSize + rampLen],
[sx, sy + tileSize + rampLen],
];
} else {
pts = [
[sx + tileSize, sy + tileSize],
[sx + tileSize - rampWidth, sy + tileSize],
[sx + tileSize - rampWidth, sy + tileSize + rampLen],
[sx + tileSize, sy + tileSize + rampLen],
];
}
svg.appendChild(newPolygon(pts, "none", color, 3));
}
function drawSecretTunnel(x, y, color, direction) {
const tunnelWidth = 6 * pxPerInch;
const tunnelLen = 2 * tileSize;
const { sx, sy } = tileTopLeft(x, y);
let pts;
if (direction === "down-left") {
pts = [
[sx, sy + tileSize],
[sx + tunnelWidth, sy + tileSize],
[sx + tunnelWidth, sy + tileSize + tunnelLen],
[sx, sy + tileSize + tunnelLen],
];
} else {
pts = [
[sx + tileSize, sy + tileSize],
[sx + tileSize - tunnelWidth, sy + tileSize],
[sx + tileSize - tunnelWidth, sy + tileSize + tunnelLen],
[sx + tileSize, sy + tileSize + tunnelLen],
];
}
svg.appendChild(newPolygon(pts, color, null, 0));
}
function drawLoadingZone(x, y, color) {
const { sx, sy } = tileTopLeft(x, y);
svg.appendChild(newRect(sx, sy, tileSize, tileSize, color));
}
function drawBaseZone(x, y, corner, color) {
const { sx, sy } = tileTopLeft(x, y);
const size = 18 * pxPerInch;
let bx = sx, by = sy;
if (corner === "left-bottom") {
bx = sx;
by = sy + tileSize - size;
}
if (corner === "right-bottom") {
bx = sx + tileSize - size;
by = sy + tileSize - size;
}
svg.appendChild(newRect(bx, by, size, size, null, color, 3));
}
function drawArtifacts(x, y, colors) {
const { sx, sy } = tileTopLeft(x, y);
const spacing = tileSize / (colors.length + 1);
colors.forEach((c, i) => {
let cx = sx - tileSize / 2 + tileSize + spacing * (i + 1);
let cy = sy + tileSize / 2;
svg.appendChild(newCircle(cx, cy, 12, c, "#000"));
});
}
// === Draw everything ===
drawGrid();
drawGoalTriangle(0, 5, blue, "blue");
drawGoalTriangle(5, 5, red, "red");
drawRamp(0, 5, blue, "down-left");
drawRamp(5, 5, red, "down-right");
drawSecretTunnel(0, 3, red, "down-left");
drawSecretTunnel(5, 3, blue, "down-right");
drawLoadingZone(0, 0, red);
drawLoadingZone(5, 0, blue);
drawBaseZone(1, 1, "right-bottom", red);
drawBaseZone(4, 1, "left-bottom", blue);
drawArtifacts(0, 1, [purple, purple, green]);
drawArtifacts(0, 2, [purple, green, purple]);
drawArtifacts(0, 3, [green, purple, purple]);
drawArtifacts(4, 1, [green, purple, purple]);
drawArtifacts(4, 2, [purple, green, purple]);
drawArtifacts(4, 3, [purple, purple, green]);
// === O B E L I S K ===
const obeliskPatterns = ["GPP", "GPG", "PPG"];
let currentPattern = "GPP";
// Rectangle
const obelisk = document.createElementNS("http://www.w3.org/2000/svg", "rect");
obelisk.setAttribute("x", 300); // adjust X position
obelisk.setAttribute("y", 20); // just above the field
obelisk.setAttribute("width", 160);
obelisk.setAttribute("height", 60);
obelisk.setAttribute("fill", "#f1f5f9");
obelisk.setAttribute("stroke", "#000");
obelisk.setAttribute("stroke-width", "2");
obelisk.style.cursor = "pointer";
svg.appendChild(obelisk);
// Text inside rectangle
const obeliskText = document.createElementNS("http://www.w3.org/2000/svg", "text");
obeliskText.setAttribute("x", 380); // center text
obeliskText.setAttribute("y", 60);
obeliskText.setAttribute("text-anchor", "middle");
obeliskText.setAttribute("dominant-baseline", "middle");
obeliskText.setAttribute("font-size", "32");
obeliskText.setAttribute("font-family", "Arial, sans-serif");
obeliskText.textContent = currentPattern;
svg.appendChild(obeliskText);
// Click to randomize pattern
obelisk.addEventListener("click", () => {
const newPattern = obeliskPatterns[Math.floor(Math.random() * obeliskPatterns.length)];
currentPattern = newPattern;
obeliskText.textContent = currentPattern;
});
};
console.log("App.js loaded!");