Clean up
This commit is contained in:
@@ -837,7 +837,7 @@
|
|||||||
return cl.getPointAtLength(b);
|
return cl.getPointAtLength(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
function edgeCollisionPosition(xc, yc, x, y, edge, radius) {
|
function edgeContactPosition(xc, yc, x, y, edge, radius) {
|
||||||
const baseSlope = slope(edge);
|
const baseSlope = slope(edge);
|
||||||
// if (Object.is(baseSlope, 0)) s.isLanded = true;
|
// if (Object.is(baseSlope, 0)) s.isLanded = true;
|
||||||
|
|
||||||
@@ -898,7 +898,7 @@
|
|||||||
return { x: x, y: y };
|
return { x: x, y: y };
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateShip(s, elapsed, edgeszz) {
|
function updateShip(s, elapsed) {
|
||||||
const degrees = getRotate(gun);
|
const degrees = getRotate(gun);
|
||||||
if (rotate > 0) gun.style.transform = `rotate(${(+degrees + rotationSpeed * elapsed) % 360}deg)`;
|
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)`;
|
else if (rotate < 0) gun.style.transform = `rotate(${(+degrees - rotationSpeed * elapsed) % 360}deg)`;
|
||||||
@@ -924,8 +924,6 @@
|
|||||||
let [xc, yc] = position;
|
let [xc, yc] = position;
|
||||||
// console.log("future position", xc, yc);
|
// console.log("future position", xc, yc);
|
||||||
|
|
||||||
const collE = getCollisionEdges(edgeszz, position);
|
|
||||||
|
|
||||||
const efs = mes.filter(({ edge, wall }) => {
|
const efs = mes.filter(({ edge, wall }) => {
|
||||||
const { xa, ya, xb, yb } = edge;
|
const { xa, ya, xb, yb } = edge;
|
||||||
const det = (xb - xa) * (y - ya) - (x - xa) * (yb - ya);
|
const det = (xb - xa) * (y - ya) - (x - xa) * (yb - ya);
|
||||||
@@ -933,35 +931,8 @@
|
|||||||
});
|
});
|
||||||
// console.log("edges facing ship", efs);
|
// 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));
|
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
|
// corners ahead of ship
|
||||||
const fCollC = getForwardCollisionCorners(ws, { x, y }, s.velocity);
|
const fCollC = getForwardCollisionCorners(ws, { x, y }, s.velocity);
|
||||||
// console.log("corners ahead of ship", fCollC);
|
// console.log("corners ahead of ship", fCollC);
|
||||||
@@ -969,18 +940,18 @@
|
|||||||
// corners within collision distance
|
// corners within collision distance
|
||||||
cwcd = fCollC.filter(withinCollisionDistance({ x, y }, s.velocity));
|
cwcd = fCollC.filter(withinCollisionDistance({ x, y }, s.velocity));
|
||||||
// console.log("corners on collision path", cwcd);
|
// console.log("corners on collision path", cwcd);
|
||||||
|
|
||||||
current = s.collision;
|
|
||||||
|
|
||||||
const cornerColl = cwcd.find(detectCornerCollision([xc, yc], [x, y], shipRadius));
|
const cornerColl = cwcd.find(detectCornerCollision([xc, yc], [x, y], shipRadius));
|
||||||
|
|
||||||
|
current = s.collision;
|
||||||
s.collision = edgeColl || cornerColl;
|
s.collision = edgeColl || cornerColl;
|
||||||
|
|
||||||
if (s.collision) console.log("COLLISION", s.collision);
|
if (s.collision) console.log("COLLISION", s.collision);
|
||||||
|
|
||||||
legs.style.display = s.gearDown ? "initial" : "none";
|
legs.style.display = s.gearDown ? "initial" : "none";
|
||||||
|
|
||||||
if (!current && s.collision) {
|
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);
|
// const baseSlope = slope(s.collision.edge);
|
||||||
// if (Object.is(baseSlope, 0) && s.gearDown) s.isLanded = true;
|
// if (Object.is(baseSlope, 0) && s.gearDown) s.isLanded = true;
|
||||||
|
|
||||||
@@ -988,7 +959,7 @@
|
|||||||
if (s.collision.corner) {
|
if (s.collision.corner) {
|
||||||
posP = cornerContactPosition(xc, yc, x, y, s.collision.corner, shipRadius);
|
posP = cornerContactPosition(xc, yc, x, y, s.collision.corner, shipRadius);
|
||||||
} else if (s.collision.edge) {
|
} 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 };
|
s.velocity = { x: 0, y: 0 };
|
||||||
@@ -1097,8 +1068,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function animate(timestamp) {
|
function animate(timestamp) {
|
||||||
// console.log("current timestamp", timestamp, "previous", previous);
|
|
||||||
|
|
||||||
const elapsed = timestamp - previous;
|
const elapsed = timestamp - previous;
|
||||||
const delta = timestamp - zero;
|
const delta = timestamp - zero;
|
||||||
let degrees = getRotate(gun);
|
let degrees = getRotate(gun);
|
||||||
@@ -1119,9 +1088,7 @@
|
|||||||
frameCount++;
|
frameCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateShip(s, elapsed);
|
||||||
// console.log("COLLISION EDGES", edgeszz);
|
|
||||||
updateShip(s, elapsed, edgeszz);
|
|
||||||
updateBullets(elapsed);
|
updateBullets(elapsed);
|
||||||
// updateEdges(position);
|
// updateEdges(position);
|
||||||
// if (!s.collision) updateLines(elapsed, edgeszz, s.position, s.velocity);
|
// if (!s.collision) updateLines(elapsed, edgeszz, s.position, s.velocity);
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 42 KiB |
Reference in New Issue
Block a user