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"?>
<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>
foreignObject {
font-size: 4pt;
@@ -155,6 +156,7 @@
acceleration: { x: 0, y: 0 },
rotate: 0,
collision: null,
isLanded: false,
node: null
};
@@ -422,7 +424,7 @@
}
function isLandable(edge) {
console.log("edge", edge, "slope", slope(edge));
// console.log("edge", edge, "slope", slope(edge));
return Object.is(slope(edge), +0);
}
@@ -442,7 +444,9 @@
const s = (1 / 2) * (da + db + 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]) {
@@ -518,29 +522,26 @@
const changeX = 0.001 * elapsed * velocityX;
const changeY = 0.001 * elapsed * velocityY;
// console.log("ship position", s.position);
let { x, y } = s.position;
let position = [positionX, positionY] = restart ? [0, 0] : wrapPos(changeX + x, changeY + y);
s.collision = detectCollisions(position, allWallCorners, findAllEdges(allEdgePts, position), getCollisionEdges(edgeszz, position));
if (s.collision && !isLandable(s.collision.edge)) {
// console.log("collision detected", s.collision, "slope", Object.is(slope(s.collision.edge), +0));
// console.log("isLandable()", isLandable(s.collision.edge));
console.log("a");
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) {
console.log("ship landed", s);
s.velocity = { x: 0, y: 0 };
console.log("b", position, s.position);
s.collision = null;
s.position = { x: positionX, y: positionY }
// ship.style.transform = `translate(${positionX}px, ${positionY}px)`;
s.node.style.transform = `translate(${positionX}px, ${positionY}px)`;
s.velocity = { x: 0, y: 0 };
s.position.y = Math.trunc(s.collision.edge.ya - 5);
s.isLanded = true;
s.node.style.transform = `translate(${s.position.x}px, ${s.position.y}px)`;
// console.log("ship landed", s, "edge", s.collision.edge.ya);
} else {
console.log("c");
s.position = { x: positionX, y: positionY }
s.node.style.transform = `translate(${positionX}px, ${positionY}px)`;
}
@@ -573,7 +574,7 @@
rotate = 0;
[...edgeContainer.children].forEach(c => c.remove());;
drawAllEdges(edgePts);
// drawAllEdges(edgePts);
allStartingEdges = findAllEdges(edgePts, position);
ship.style.transform = "";
walls.forEach(w => w.setAttribute('fill', 'black'));
@@ -612,7 +613,7 @@
// position = updateShip(s, elapsed);
updateShip(s, elapsed);
updateBullets(elapsed);
updateEdges(position);
// updateEdges(position);
if (drawCollisionLines) updateTriangles(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("landable?", isLandable(collision));
console.log("collision", s.collision);
if (s.collision) {
// console.log("collision", s.collision);
if (s.collision && !s.isLanded) {
started = false;
isReadingKeys = false;
walls.forEach(w => w.setAttribute('fill', 'red'));
@@ -635,8 +636,8 @@
time.innerText = 0;
}
const finished = edgeContainer.childElementCount <= 0;
if (finished) started = false;
// const finished = edgeContainer.childElementCount <= 0;
// if (finished) started = false;
if (started) {
time.innerText = ((timestamp - zeroForTimer) * 0.001).toFixed(3);

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB