This commit is contained in:
2025-12-28 14:23:22 -08:00
parent 4903812ca1
commit e8cc4e5241

View File

@@ -109,9 +109,9 @@
</g>
<!-- <polygon class="wall" points="20,20 30,20 40,40 20,40" /> -->
<!-- <polygon class="wall" points="20,20 20,10 30,10 30,20 40,40 10,40" /> -->
<polygon class="wall" points="20,20 20,10 30,10 30,20 40,40 10,40" />
<!-- <polygon class="wall" points="-10,20 10,10 10,20" /> -->
<polygon class="wall" points="20,20 40,20 40,40 20,40" />
<!-- <polygon class="wall" points="20,20 40,20 40,40 20,40" /> -->
<!-- <polygon class="wall" points="10,10 20,10 20,20 10,20" /> -->
<!-- <polygon class="wall" points="20,-50 -50,-50 -60,-70 -50,-100 80,-100 80,-90 -20,-90 -20,-60 40,-60 40,40 20,40" /> -->
<!-- <polygon class="wall" points="-10,-30 -10,-40 30,-50 60,-30 80,0 150,0 150,10 60,50 -10,40 -20,20 20,20 20,-20" /> -->
@@ -253,16 +253,10 @@
return { node: wall, edges: es };
});
// console.log("edgeszz", edgeszz);
// console.log("wall corners", allWallCorners);
const allEdgePts = allWallCorners.map(w =>
w.map((pt, i, arr) => [pt, arr[(i + 1) % arr.length]])
);
// console.log("all edge points", allEdgePts);
let allStartingEdges;
init(allEdgePts);
@@ -487,7 +481,6 @@
}
function slope({ xa, ya, xb, yb }) {
// const [[xa, ya], [xb, yb]] = edge.split(' ').map(n => n.split(',').map(n => +n));
return (yb - ya) / (xb - xa);
}
@@ -520,40 +513,19 @@
}
function detectCollisions(position, walls, edges, z) {
// console.log("edges to test for collision", edgesToCheck);
// console.log("walls", walls);
// this returns the wall with the corner, no the corner
let actualCorner;
const corner = walls.find(wall => {
// console.log("checking corners on wall", wall);
const c = wall.find(corner => detectCornerCollision(position, corner));
// console.log("corner", c);
actualCorner = c;
// console.log("c", c);
return c;
});
// console.log("actual corner", actualCorner);
// if (corner) console.log("corner collision", corner);
const edge = z.find(({ edge: pts, node: ee }) => {
const str = `${pts.xa},${pts.ya} ${pts.xb},${pts.yb}`;
return detectEdgeCollision(position, pts);
}
);
// if (found) console.log("found", found.node, found.node.node.classList.contains("inverse"));
// return [
// [walls, wall => wall.some(corner => detectCornerCollision(position, corner))],
// [edges, edge => {
// const coll = detectEdgeCollision(position, edge);
// if (coll) console.log(edge, slope(edge) == -0);
// return coll;
// }]
// ].some(([t, f]) => t.some(f))
return edge || actualCorner;
}
@@ -660,22 +632,13 @@
}
function updateLines(elapsed, edges, currentPos, futurePos) {
// console.log("velocity", s.velocity);
// console.log("collision", s.collision);
// console.log("edges", edges);
// const edgeIds = [...linesContainer.children].map(c => c.id);
const edgeIds = edges.map(({edge: { xa, ya, xb, yb }}) => `normal${xa}-${ya}-${xb}-${yb}`);
const nodes = [...linesContainer.children];
// console.log("EDGE IDS", edgeIds, "NODES", nodes);
nodes.forEach(n => {
if (!edgeIds.includes(n.id)) n.remove();
});
console.log("update lines", currentPos, futurePos);
edges.forEach(({ edge: { xa, ya, xb, yb }}) => {
const id = `normal${xa}-${ya}-${xb}-${yb}`;
const g = linesContainer.querySelector(`#${id}`) || document.createElementNS(namespaceURIsvg, 'g');
@@ -791,18 +754,11 @@
}
updateShip(s, elapsed, edgeszz);
// console.log("S POSITION", s.position);
updateBullets(elapsed);
// updateEdges(position);
// if (!s.collision) updateLines(elapsed, collE, {x, y}, s.position);
if (drawCollisionLines) updateTriangles(position);
// const collision = detectCollisions(position, allWallCorners, findAllEdges(allEdgePts, position), getCollisionEdges(edgeszz, position));
// console.log("collision", collision && collision.hasOwnProperty("edge"));
// console.log("landable?", isLandable(collision));
// console.log("collision", s.collision);
if (s.collision && !s.isLanded) {
console.log(s.collision);
started = false;
@@ -969,7 +925,7 @@
const svgP = pointerPt.matrixTransform(svg.getScreenCTM().inverse());
if (bg.isPointInFill(svgP)) {
console.log(Math.trunc(svgP.x), Math.trunc(svgP.y));
// console.log(Math.trunc(svgP.x), Math.trunc(svgP.y));
xp.innerText = Math.trunc(svgP.x);
yp.innerText = Math.trunc(svgP.y);

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 30 KiB