This commit is contained in:
2025-12-25 16:57:10 -08:00
parent d732fe0bf1
commit 722e8172ab

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg viewBox="-200 -150 400 300" version="1.1" xmlns="http://www.w3.org/2000/svg"> <!-- <svg viewBox="-200 -150 400 300" version="1.1" xmlns="http://www.w3.org/2000/svg"> -->
<svg viewBox="-10 -10 50 50" version="1.1" xmlns="http://www.w3.org/2000/svg">
<style> <style>
foreignObject { foreignObject {
font-size: 4pt; font-size: 4pt;
@@ -155,6 +156,7 @@
acceleration: { x: 0, y: 0 }, acceleration: { x: 0, y: 0 },
rotate: 0, rotate: 0,
collision: null, collision: null,
isLanded: false,
node: null node: null
}; };
@@ -422,7 +424,7 @@
} }
function isLandable(edge) { function isLandable(edge) {
console.log("edge", edge, "slope", slope(edge)); // console.log("edge", edge, "slope", slope(edge));
return Object.is(slope(edge), +0); return Object.is(slope(edge), +0);
} }
@@ -442,7 +444,9 @@
const s = (1 / 2) * (da + db + dc); const s = (1 / 2) * (da + db + dc);
const hc = (2 / dc) * Math.sqrt(s * (s - da) * (s - db) * (s - dc)); const hc = (2 / dc) * Math.sqrt(s * (s - da) * (s - db) * (s - dc));
return hc <= shipRadius; return +hc.toFixed(2) <= shipRadius;
// console.log("hc", );
// return hc <= shipRadius;
} }
function detectCornerCollision([xc, yc], [x, y]) { function detectCornerCollision([xc, yc], [x, y]) {
@@ -518,29 +522,26 @@
const changeX = 0.001 * elapsed * velocityX; const changeX = 0.001 * elapsed * velocityX;
const changeY = 0.001 * elapsed * velocityY; const changeY = 0.001 * elapsed * velocityY;
// console.log("ship position", s.position);
let { x, y } = s.position; let { x, y } = s.position;
let position = [positionX, positionY] = restart ? [0, 0] : wrapPos(changeX + x, changeY + y); let position = [positionX, positionY] = restart ? [0, 0] : wrapPos(changeX + x, changeY + y);
s.collision = detectCollisions(position, allWallCorners, findAllEdges(allEdgePts, position), getCollisionEdges(edgeszz, position)); s.collision = detectCollisions(position, allWallCorners, findAllEdges(allEdgePts, position), getCollisionEdges(edgeszz, position));
if (s.collision && !isLandable(s.collision.edge)) { if (s.collision && !isLandable(s.collision.edge)) {
// console.log("collision detected", s.collision, "slope", Object.is(slope(s.collision.edge), +0)); console.log("a");
// console.log("isLandable()", isLandable(s.collision.edge));
s.velocity = { x: 0, y: 0 }; s.velocity = { x: 0, y: 0 };
// s.position = { x: 0, y: 0 }
// s.node.style.transform = `translate(${0}px, ${0}px)`;
// s.position = { x: positionX, y: positionY }
console.log("ship", s);
} else if (s.collision) { } else if (s.collision) {
console.log("ship landed", s); console.log("b", position, s.position);
s.velocity = { x: 0, y: 0 };
s.collision = null; s.velocity = { x: 0, y: 0 };
s.position = { x: positionX, y: positionY } s.position.y = Math.trunc(s.collision.edge.ya - 5);
// ship.style.transform = `translate(${positionX}px, ${positionY}px)`; s.isLanded = true;
s.node.style.transform = `translate(${positionX}px, ${positionY}px)`; s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
// console.log("ship landed", s, "edge", s.collision.edge.ya);
} else { } else {
console.log("c");
s.position = { x: positionX, y: positionY } s.position = { x: positionX, y: positionY }
s.node.style.transform = `translate(${positionX}px, ${positionY}px)`; s.node.style.transform = `translate(${positionX}px, ${positionY}px)`;
} }
@@ -573,7 +574,7 @@
rotate = 0; rotate = 0;
[...edgeContainer.children].forEach(c => c.remove());; [...edgeContainer.children].forEach(c => c.remove());;
drawAllEdges(edgePts); // drawAllEdges(edgePts);
allStartingEdges = findAllEdges(edgePts, position); allStartingEdges = findAllEdges(edgePts, position);
ship.style.transform = ""; ship.style.transform = "";
walls.forEach(w => w.setAttribute('fill', 'black')); walls.forEach(w => w.setAttribute('fill', 'black'));
@@ -612,7 +613,7 @@
// position = updateShip(s, elapsed); // position = updateShip(s, elapsed);
updateShip(s, elapsed); updateShip(s, elapsed);
updateBullets(elapsed); updateBullets(elapsed);
updateEdges(position); // updateEdges(position);
if (drawCollisionLines) updateTriangles(position); if (drawCollisionLines) updateTriangles(position);
// const collision = detectCollisions(position, allWallCorners, findAllEdges(allEdgePts, position), getCollisionEdges(edgeszz, position)); // const collision = detectCollisions(position, allWallCorners, findAllEdges(allEdgePts, position), getCollisionEdges(edgeszz, position));
@@ -620,8 +621,8 @@
// console.log("collision", collision && collision.hasOwnProperty("edge")); // console.log("collision", collision && collision.hasOwnProperty("edge"));
// console.log("landable?", isLandable(collision)); // console.log("landable?", isLandable(collision));
console.log("collision", s.collision); // console.log("collision", s.collision);
if (s.collision) { if (s.collision && !s.isLanded) {
started = false; started = false;
isReadingKeys = false; isReadingKeys = false;
walls.forEach(w => w.setAttribute('fill', 'red')); walls.forEach(w => w.setAttribute('fill', 'red'));
@@ -635,8 +636,8 @@
time.innerText = 0; time.innerText = 0;
} }
const finished = edgeContainer.childElementCount <= 0; // const finished = edgeContainer.childElementCount <= 0;
if (finished) started = false; // if (finished) started = false;
if (started) { if (started) {
time.innerText = ((timestamp - zeroForTimer) * 0.001).toFixed(3); time.innerText = ((timestamp - zeroForTimer) * 0.001).toFixed(3);

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB