diff --git a/html/images/space.svg b/html/images/space.svg index 59b6dd4..1c82a66 100644 --- a/html/images/space.svg +++ b/html/images/space.svg @@ -837,7 +837,7 @@ return cl.getPointAtLength(b); } - function edgeCollisionPosition(xc, yc, x, y, edge, radius) { + function edgeContactPosition(xc, yc, x, y, edge, radius) { const baseSlope = slope(edge); // if (Object.is(baseSlope, 0)) s.isLanded = true; @@ -898,7 +898,7 @@ return { x: x, y: y }; } - function updateShip(s, elapsed, edgeszz) { + function updateShip(s, elapsed) { const degrees = getRotate(gun); if (rotate > 0) gun.style.transform = `rotate(${(+degrees + rotationSpeed * elapsed) % 360}deg)`; else if (rotate < 0) gun.style.transform = `rotate(${(+degrees - rotationSpeed * elapsed) % 360}deg)`; @@ -924,8 +924,6 @@ let [xc, yc] = position; // console.log("future position", xc, yc); - const collE = getCollisionEdges(edgeszz, position); - const efs = mes.filter(({ edge, wall }) => { const { xa, ya, xb, yb } = edge; const det = (xb - xa) * (y - ya) - (x - xa) * (yb - ya); @@ -933,35 +931,8 @@ }); // console.log("edges facing ship", efs); - // const positionSeg = { xa: x, ya: y, xb: xc, yb: yc }; - - // console.log("positionSeg", positionSeg); - const edgeColl = efs.find(detectEdgeCollision([xc, yc], [x, y], shipRadius)); - // efs.forEach(({ edge, wall }) => { - // const { xa, ya, xb, yb } = edge; - // const sl = slope(edge); - // if (sl === Infinity) { - // drawLine(xa + shipRadius, ya, xb + shipRadius, yb); - // } else if (sl === -Infinity) { - // drawLine(xa - shipRadius, ya, xb - shipRadius, yb); - // } else if (Object.is(sl, -0)) { - // drawLine(xa, ya + shipRadius, xb, yb + shipRadius); - // } else if (sl === 0) { - // drawLine(xa, ya - shipRadius, xb, yb - shipRadius); - // } else { - // const rise = yb - ya; - // const run = xb - xa; - // const length = distance(xa, ya, xb, yb) - // - // const riol = rise / length * shipRadius; - // const ruol = run / length * shipRadius; - // - // drawLine(xa + riol, ya - ruol, xb + riol, yb - ruol); - // } - // }); - // corners ahead of ship const fCollC = getForwardCollisionCorners(ws, { x, y }, s.velocity); // console.log("corners ahead of ship", fCollC); @@ -969,18 +940,18 @@ // corners within collision distance cwcd = fCollC.filter(withinCollisionDistance({ x, y }, s.velocity)); // console.log("corners on collision path", cwcd); - - current = s.collision; - const cornerColl = cwcd.find(detectCornerCollision([xc, yc], [x, y], shipRadius)); + current = s.collision; s.collision = edgeColl || cornerColl; - if (s.collision) console.log("COLLISION", s.collision); legs.style.display = s.gearDown ? "initial" : "none"; if (!current && s.collision) { + // just check if ya and yb are == ?, but then how do you know if the + // edge is facing up or down? compare xs? + // const baseSlope = slope(s.collision.edge); // if (Object.is(baseSlope, 0) && s.gearDown) s.isLanded = true; @@ -988,7 +959,7 @@ if (s.collision.corner) { posP = cornerContactPosition(xc, yc, x, y, s.collision.corner, shipRadius); } else if (s.collision.edge) { - posP = edgeCollisionPosition(xc, yc, x, y, s.collision.edge, shipRadius); + posP = edgeContactPosition(xc, yc, x, y, s.collision.edge, shipRadius); } s.velocity = { x: 0, y: 0 }; @@ -1097,8 +1068,6 @@ } function animate(timestamp) { - // console.log("current timestamp", timestamp, "previous", previous); - const elapsed = timestamp - previous; const delta = timestamp - zero; let degrees = getRotate(gun); @@ -1119,9 +1088,7 @@ frameCount++; } - - // console.log("COLLISION EDGES", edgeszz); - updateShip(s, elapsed, edgeszz); + updateShip(s, elapsed); updateBullets(elapsed); // updateEdges(position); // if (!s.collision) updateLines(elapsed, edgeszz, s.position, s.velocity);