Rename variable
This commit is contained in:
@@ -140,14 +140,14 @@
|
|||||||
const pt = svg.createSVGPoint();
|
const pt = svg.createSVGPoint();
|
||||||
const cornerPt = svg.createSVGPoint();
|
const cornerPt = svg.createSVGPoint();
|
||||||
|
|
||||||
const points = wall.getAttribute('points').split(' ').map(coords => {
|
const wallCorners = wall.getAttribute('points').split(' ').map(coords => {
|
||||||
const [x, y] = coords.split(',');
|
const [x, y] = coords.split(',');
|
||||||
return [+x, +y];
|
return [+x, +y];
|
||||||
});
|
});
|
||||||
|
|
||||||
const triangleContainer = document.querySelector('#triangles');
|
const triangleContainer = document.querySelector('#triangles');
|
||||||
const lineContainer = document.querySelector('#lines');
|
const lineContainer = document.querySelector('#lines');
|
||||||
const edgePts = points.map((pt, i) => [pt, points[(i + 1) % points.length]]);
|
const edgePts = wallCorners.map((pt, i) => [pt, wallCorners[(i + 1) % wallCorners.length]]);
|
||||||
const drawCollisionLines = false;
|
const drawCollisionLines = false;
|
||||||
|
|
||||||
function drawEdges(lpts) {
|
function drawEdges(lpts) {
|
||||||
@@ -339,8 +339,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function detectCollision(points, [xc, yc], edges) {
|
function detectCollision(corners, [xc, yc], edges) {
|
||||||
const cornerCollision = points.some(([x, y]) => {
|
const cornerCollision = corners.some(([x, y]) => {
|
||||||
cornerPt.x = x - xc;
|
cornerPt.x = x - xc;
|
||||||
cornerPt.y = y - yc;
|
cornerPt.y = y - yc;
|
||||||
|
|
||||||
@@ -466,7 +466,7 @@
|
|||||||
drawEdges(edgePts);
|
drawEdges(edgePts);
|
||||||
}
|
}
|
||||||
|
|
||||||
const collision = detectCollision(points, position, findEdges(edgePts, position));
|
const collision = detectCollision(wallCorners, position, findEdges(edgePts, position));
|
||||||
wall.setAttribute('fill', collision ? 'red' : 'black');
|
wall.setAttribute('fill', collision ? 'red' : 'black');
|
||||||
|
|
||||||
if (collision) {
|
if (collision) {
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 18 KiB |
Reference in New Issue
Block a user