Clean up
This commit is contained in:
@@ -109,9 +109,9 @@
|
|||||||
</g>
|
</g>
|
||||||
|
|
||||||
<!-- <polygon class="wall" points="20,20 30,20 40,40 20,40" /> -->
|
<!-- <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="-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="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="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" /> -->
|
<!-- <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 };
|
return { node: wall, edges: es };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// console.log("edgeszz", edgeszz);
|
|
||||||
// console.log("wall corners", allWallCorners);
|
|
||||||
|
|
||||||
const allEdgePts = allWallCorners.map(w =>
|
const allEdgePts = allWallCorners.map(w =>
|
||||||
w.map((pt, i, arr) => [pt, arr[(i + 1) % arr.length]])
|
w.map((pt, i, arr) => [pt, arr[(i + 1) % arr.length]])
|
||||||
);
|
);
|
||||||
|
|
||||||
// console.log("all edge points", allEdgePts);
|
|
||||||
|
|
||||||
let allStartingEdges;
|
let allStartingEdges;
|
||||||
init(allEdgePts);
|
init(allEdgePts);
|
||||||
|
|
||||||
@@ -487,7 +481,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function slope({ xa, ya, xb, yb }) {
|
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);
|
return (yb - ya) / (xb - xa);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,40 +513,19 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function detectCollisions(position, walls, edges, z) {
|
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;
|
let actualCorner;
|
||||||
const corner = walls.find(wall => {
|
const corner = walls.find(wall => {
|
||||||
// console.log("checking corners on wall", wall);
|
|
||||||
const c = wall.find(corner => detectCornerCollision(position, corner));
|
const c = wall.find(corner => detectCornerCollision(position, corner));
|
||||||
// console.log("corner", c);
|
|
||||||
actualCorner = c;
|
actualCorner = c;
|
||||||
// console.log("c", c);
|
|
||||||
return c;
|
return c;
|
||||||
});
|
});
|
||||||
|
|
||||||
// console.log("actual corner", actualCorner);
|
|
||||||
// if (corner) console.log("corner collision", corner);
|
|
||||||
|
|
||||||
const edge = z.find(({ edge: pts, node: ee }) => {
|
const edge = z.find(({ edge: pts, node: ee }) => {
|
||||||
const str = `${pts.xa},${pts.ya} ${pts.xb},${pts.yb}`;
|
const str = `${pts.xa},${pts.ya} ${pts.xb},${pts.yb}`;
|
||||||
return detectEdgeCollision(position, pts);
|
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;
|
return edge || actualCorner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,22 +632,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateLines(elapsed, edges, currentPos, futurePos) {
|
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 edgeIds = edges.map(({edge: { xa, ya, xb, yb }}) => `normal${xa}-${ya}-${xb}-${yb}`);
|
||||||
const nodes = [...linesContainer.children];
|
const nodes = [...linesContainer.children];
|
||||||
|
|
||||||
// console.log("EDGE IDS", edgeIds, "NODES", nodes);
|
|
||||||
|
|
||||||
nodes.forEach(n => {
|
nodes.forEach(n => {
|
||||||
if (!edgeIds.includes(n.id)) n.remove();
|
if (!edgeIds.includes(n.id)) n.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log("update lines", currentPos, futurePos);
|
|
||||||
|
|
||||||
edges.forEach(({ edge: { xa, ya, xb, yb }}) => {
|
edges.forEach(({ edge: { xa, ya, xb, yb }}) => {
|
||||||
const id = `normal${xa}-${ya}-${xb}-${yb}`;
|
const id = `normal${xa}-${ya}-${xb}-${yb}`;
|
||||||
const g = linesContainer.querySelector(`#${id}`) || document.createElementNS(namespaceURIsvg, 'g');
|
const g = linesContainer.querySelector(`#${id}`) || document.createElementNS(namespaceURIsvg, 'g');
|
||||||
@@ -791,18 +754,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateShip(s, elapsed, edgeszz);
|
updateShip(s, elapsed, edgeszz);
|
||||||
// console.log("S POSITION", s.position);
|
|
||||||
updateBullets(elapsed);
|
updateBullets(elapsed);
|
||||||
// updateEdges(position);
|
// updateEdges(position);
|
||||||
// if (!s.collision) updateLines(elapsed, collE, {x, y}, s.position);
|
// if (!s.collision) updateLines(elapsed, collE, {x, y}, s.position);
|
||||||
if (drawCollisionLines) updateTriangles(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) {
|
if (s.collision && !s.isLanded) {
|
||||||
console.log(s.collision);
|
console.log(s.collision);
|
||||||
started = false;
|
started = false;
|
||||||
@@ -969,7 +925,7 @@
|
|||||||
const svgP = pointerPt.matrixTransform(svg.getScreenCTM().inverse());
|
const svgP = pointerPt.matrixTransform(svg.getScreenCTM().inverse());
|
||||||
|
|
||||||
if (bg.isPointInFill(svgP)) {
|
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);
|
xp.innerText = Math.trunc(svgP.x);
|
||||||
yp.innerText = Math.trunc(svgP.y);
|
yp.innerText = Math.trunc(svgP.y);
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 30 KiB |
Reference in New Issue
Block a user